18

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.

1 Answer 1

30

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
24

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.

4
  • 1
    Worth mentioning that not all aplications will recover from having their streams cut.
    – Aurelia
    Apr 3, 2015 at 15:44
  • 1
    Get the module number by sink name: MODULE_NUMBER=$(pacmd list-sinks | grep -E "^\s*name:|^\s*module:" | grep -A 1 -E "^\s*name: <MY-SINK-NAME>" | grep -oP "module: \K[0-9]+") where MY-SINK-NAME is what it says. Keep the < > in the code!
    – KrisWebDev
    Jan 24, 2016 at 13:26
  • 1
    @KrisWebDev: thanks, added a line on how to get module indices for a more general aproach.
    – Takkat
    Jan 24, 2016 at 14:24
  • Great, then this becomes: pactl list short modules | grep "sink_name=MY-SINK-NAME" | cut -f1 | xargs -L1 pactl unload-module. It has the advantage of deleting ALL modules named MY-SINK-NAME (sink names are not unique).
    – KrisWebDev
    Jan 24, 2016 at 14:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .