Skip to content

Creating Dummy Audio

Reason

To test audio on a system having no audio sink or Docker container in a CI-pipline, and it is needed for unit-testing.

Shell Script

Create a dummy audio sink when does not exist yet.

#!/usr/bin/env bash

# Start a PulseAudio daemon only if no audio server (PulseAudio or
# PipeWire's PulseAudio compatibility layer) is reachable yet.
# --exit-idle-time=-1 keeps the daemon running even when no clients are connected.
if ! pactl info >/dev/null 2>&1; then
    pulseaudio --daemonize=true --exit-idle-time=-1
fi

# Create a virtual null sink named "dummy", but only if it doesn't exist yet,
# so repeated runs don't stack up duplicate sinks.
# Qt ignores the built-in "auto_null" placeholder, so a differently named sink
# is needed for audioOutputs() to report an output device.
pactl list short sinks | grep -q '\bdummy\b' ||
    pactl load-module module-null-sink sink_name=dummy \
        sink_properties=device.description=Dummy

# Make the "dummy" sink the default output, so applications that don't pick
# a device explicitly (like the TTS plugin) use it.
pactl set-default-sink dummy