Ubuntu – Pulseaudio loopback unload audio output devices


I'm trying to find out how to unload pulseaudio loopback outputs. I'm using pulseaudio to create a loopback mix to capture my microphone and system audio for streaming. Every time I launch my script which has this code:

pactl load-module module-null-sink sink_name=mix 
pactl load-module module-loopback sink=mix
pactl load-module module-loopback sink=mix

avconv ...

pactl unload-module module-loopback

it leaves two output devices behind after it closes. The unload-module command gets rid of the recording one but I can't find a command for the outputs.

Best Answer

The appropriate way to unload modules

Unloading a module loaded to Pulse Audio is done by the module's index number, which is given on loading:

pactl load-module module-null-sink sink_name=test

In the above example Pulseaudio server loaded the module with index id 24. This module can be unloaded with the following command:

pactl unload-module 24

Your script will have to parse the output of pactl.

In case we do not know the module number we can issue the following command which will display the number and the module name:

pactl list short modules

Newer versions also allow unloading by name:

pactl unload-module <name>

The quick and dirty method

If pulseaudio is set up as auto-spawning demon (which should be the default begaviour) we may quickly unload all modules loaded after login with a reset of the PulseAudio server to load the default modules defined in our default.pa by running:

pulseaudio -k

This will effectively unload all modules from your script and will load the default sink for output.

Related Question