Bash sound question...

Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
User avatar
invex
Level 4
Level 4
Posts: 219
Joined: Sun Aug 14, 2016 12:38 pm

Bash sound question...

Post by invex »

I'd like to add a script to startup which would allow only one application (RadioTray) to play sound and mute all other sounds.
(It's for a sort of kiosk setup.)
Is it possible?
TIA
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
rene
Level 20
Level 20
Posts: 12240
Joined: Sun Mar 27, 2016 6:58 pm

Re: Bash sound question...

Post by rene »

invex wrote: Sun Sep 30, 2018 4:25 pm Is it possible?
Not nicely. It is possible to script around pactl list sink-inputs once applications are in fact up and running but I can not see a way to mute/deny any beforehand; to set a Pulseaudio sink "to exclusive mode" if you will. Certainly the most intrinsic quality of Pulseaudio is being as opaque as possible for open source so I'll not guarantee this to mean that indeed you can't, but...

What does immediately come to mind is foregoing Pulseaudio and having Radio Tray use ALSA; more specifically a non-mixing ALSA device so as to give it exclusive access to the sound device; to deny any subsequent opens. Unfortunately this is also not completely straightforward though: Radio Tray does not allow configuration; uses the GStreamer framework which unless instructed otherwise automatically selects "an appropriate audio sink" which on Mint ends up being Pulseaudio.

Now, given that Radio Tray is a Python application, not allowing configuration is of course somewhat relative. Referring specifically to the version of Radio Tray available from the Ubuntu 18.04/Mint 19 repositories, sudo apt-get install radiotray, you can change things through:

Code: Select all

--- /usr/lib/python2.7/dist-packages/radiotray/AudioPlayerGStreamer.py.orig	2018-09-30 23:10:07.460210693 +0200
+++ /usr/lib/python2.7/dist-packages/radiotray/AudioPlayerGStreamer.py	2018-09-30 23:10:07.460210693 +0200
@@ -60,6 +60,10 @@
         fakesink = Gst.ElementFactory.make("fakesink", "fakesink")
         self.player.set_property("video-sink", fakesink)
 
+        alsasink = Gst.ElementFactory.make("alsasink", "alsasink")
+        alsasink.set_property("device", "hw:0")
+        self.player.set_property("audio-sink", alsasink)
+
         #buffer size
         if(cfg_provider._settingExists("buffer_size")):
             bufferSize = int(cfg_provider.getConfigValue("buffer_size"))
In this it is important that you pick the correct device to use. If you were to not set the "device" property the "default" device would once again end up being Pulseaudio, only now routed through ALSA; the shown "hw:0" device works if that one is in fact the underlying ALSA device of your default Pulseaudio sink. You want to check via

Code: Select all

pacmd list-sinks | sed -n '/\s*\* index:/,/\s*index:/ { /device\.string\s*=/s/.*=\s*//p }'
and replace "hw:0" with the output. You may also try "sysdefault"; a listing of all available ALSA devices you get with aplay -L.

If you after the change fire up Radio Tray and set it playing indeed something like Rhythmbox will be unable to open the audio device so... well, sort of does what you want, even if in rather icky manner. Personally I'd at this point decide to have researched it to be "impossible" but YMMV...
User avatar
invex
Level 4
Level 4
Posts: 219
Joined: Sun Aug 14, 2016 12:38 pm

Re: Bash sound question...

Post by invex »

Thank you VERY much!
I'll try.
Locked

Return to “Sound”