Where do I find the Audio selection GUI scripts?
-
Hi so I have a script that works in the RaspianOS desktop environment.
I then tried to copy the script into,
~/RetroPie/retropiemenuit shows up in the list of menu items but when I run it nothing happens.
Is there something special I need to have in my script to make it work inside Emulationstation?This is it currently:
#!/usr/bin/env bash # Script to change audio out device on a RPi4. # Tested on RPi4, Buster 32bit, Kernel 5.10, pulseaudio. # Not tested with HDMI2. Works with Apple AirPods (Bluetooth). function gui() { cmd=(pactl list sinks short) IFS=$'\n' read -r -d '' -a array < <( ${cmd[@]} && printf '\0' ) #arraylen=${#array[@]} local options=() count=0 for i in "${array[@]}" do echo "$i" | cut -f 2 options+=($count "$i") ((count++)) done dialogCmd=(dialog --menu "Choose Audio output" 22 100 16) choice=$("${dialogCmd[@]}" "${options[@]}" 2>&1 >/dev/tty) newSink=$(echo ${array[$choice]}|cut '-d ' -f1) pactl list short sink-inputs|while read stream; do streamId=$(echo $stream|cut '-d ' -f1) echo "moving stream $streamId to sink $newSink" pactl move-sink-input "$streamId" "$newSink" done } gui
UPDATE: Actually I do get the dialog menu but it doesn't do the switch as it consistently does on the desktop. Could it be because there's no active audio returned by 'pactl list short sink-inputs' ? As the script relies on having that source id to move.
Does Emulationstation get shut down when running scripts?
Is there a way to keep it running?
-
@redmarsbluemoon said in Where do I find the Audio selection GUI scripts?:
Does Emulationstation get shut down when running scripts?
EmulationStation disables the video and input processing and goes into background when something is launched.
Is there a way to keep it running?
Why ?
-
To be able to switch audio on the fly 'pactl move-sink-input' needs the Id of a currently active audio stream and that's not listed when running the command presumably because ES is backgrounded then.
I also notice that the Bluetooth control menu does not let me connect to my Bluetooth speakers (airpods) though they work perfectly on the RPiOS desktop.
But the first issue is that actually I was correct the first time and that the above script does not even show the dialog menu when running. I only get to see the menu when launching Emulationstation from a Desktop shell.
-
To be able to switch audio on the fly 'pactl move-sink-input' needs the Id of a currently active audio stream and that's not listed when running the command presumably because ES is backgrounded then.
Why do you think that ? ES is just a front-end.
I also notice that the Bluetooth control menu does not let me connect to my Bluetooth speakers (airpods) though they work perfectly on the RPiOS desktop.
The BT menu is geared toward input device, some other types of clients may not work so well.
But the first issue is that actually I was correct the first time and that the above script does not even show the dialog menu when running. I only get to see the menu when launching Emulationstation from a Desktop shell.
If you run it from the shell, outside of the desktop, does it work ?
-
It works as far as giving me the menu with two audiodevices, the jack and the hdmi1.
When running from ES I don't get the menu. I can fleetingly see some printout messages but I don't have time to read it as ES starts up again. -
@redmarsbluemoon Exit ES (F4 or just quit from the menu), then run your script and you'll see the errors.
-
@mitu
Unfortunately it seems like the terminal I end up in after quitting ES has cleared previous outputs, or its a different tty. The text is no longer there.
I have tried to find other active tty's but don't think there are any.Ah, you said to run again. Ok I did that too now and I don't see the output when running my script.
I think I need to do some more problem solving. I just made a new tiny minimal script with a menu and that works. So just need to see what breaks.
-
@mitu
I'm seeing that pulseaudio is not actually running when ES is on.
I'm getting the error 'pa_context() failed'.I'd be interested to know if that is knowingly turned off for ES as it is on when running the Desktop?
I tried starting PA up again at the start of my script and that gets me a bit further. But now I see only one of the Audio out devices. If I close down ES and run the script from the prompt I get the usual two (Jack + HDMI1)
-
I realised that this was a fresh microcard and I was still on the 5.4 kernel so ran an update-upgrade to get onto 5.10.
I made a new little script to run that just checks for pulse audio with
pulseaudio --check -v pactl info
That's showing me that now pa seems to be actually running and I don't get the pa_context() error.
Not sure if that was the kernel upgrade or something else.Also if I run my main script twice I get the two out devices on the second run.
Still, the switch does not happen and when I get back into ES the same device is active no matter what I do in my script. (which works on desktop)
I feel like ES or Retropie is overriding the audio device choice somehow?
Or maybe not using pulseaudio even when it seems to be running? And that's why my pulseaudio switching doesn't take? -
EmulationStation doesn't use PulseAudio, it uses ALSA for audio.
Also, the kernel update has no influence on how PulseAudio is initialized/working, it's most likely other updates - the Dec 2020 updates include PulseAudio if you have the desktop installed (as a dependency).What might happen is that ALSA's default card is set to PulseAudio and this might trigger the PulseAudio starting. AFAIK (and this is how RetroPie's Audio menu works) PulseAudio is started on-demand as a user service. If you want to make sure that it's started before your script, try to initialize it (with
systemctl
) before EmulationStation starts, in theautostart.sh
script. -
Ok I see.
So, EmulationStation and its emulator cores use ALSA and not PulseAudio so I shouldn't be doing anything with PulseAudio to get the switching to Bluetooth output.I should just focus on getting ALSA to work with my Bluetooth headphones.
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.