Search code examples
gstreamerpulseaudio

Switch puls audio record stream for gstreamer pipeline


I currently try to capture the audio playback from my computer and forward it to an icecast2 server, sothat I am able to listen the computer playback on my internet radios.

Therefore I first grep the correct soundcard with:

pactl list | grep -A2 'Source #' | grep 'Name: ' | cut -d" " -f2

and open a gstreamer pipline with:

gst-launch-1.0 pulsesrc device=alsa_output.pci-0000_00_1b.0.analog-stereo.monitor ! audioconvert ! lamemp3enc target=1 bitrate=128 cbr=true ! shout2send ip=127.0.0.1 port=8000 password=XXXXX mount=mystream.mp3

After performing the above mentioned commands I can go to pavucontrol->record and switch the record stream to "Monitor of Internal Analog Audio".

So far everything is working and a can listen to the stream on my internet radio.

Now I would like to perform the steps in a script to automatically start the stream at bootup. Unfortunately I could not find out how I can switch record stream (which I did before with pavucontrol) in a script.

BR webbolle


Solution

  • It is possible create a script which change the audio source device for the pavucontrol->record tab with the following commands:

    #get the id of the Record device
    ID=`pactl list | grep -E "(Source\sOutput|media\.name)" | grep Record\ Stream -B1 | grep -o -E -m1 "[0-9]+"`
    
    #switch the record device to analog-stereo.monitor
    pactl move-source-output $ID alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
    

    I think the regex I use to get the source ID of the record stream is very ugly. If somebody has a better way please let me know :-).

    BR webbolle