I need a general way to select audio output of ALSA from bash or sh script. Script should work on different platforms, no knowledge about installed audio devices.
So best should be to have 2 scripts: 1) output list of audio outputs and 2) script to select and activate desired output
Question seem trivial but I googled a lot and cannot find solution yet. For example, on Raspberry Pi3 aplay shows me
$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
Subdevices: 8/8
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
Subdevice #4: subdevice #4
Subdevice #5: subdevice #5
Subdevice #6: subdevice #6
Subdevice #7: subdevice #7
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
Subdevices: 1/1
Subdevice #0: subdevice #0
and obvious solution like play on HDMI with "aplay -D hw:0,1 music.wav" does not work.
The only found solution to switch between HDMI and Jack on Raspberry I found is amixer cset numid=3 2
for jack and amixer cset numid=3 1
for HDMI.
$ amixer controls
numid=3,iface=MIXER,name='PCM Playback Route'
numid=2,iface=MIXER,name='PCM Playback Switch'
numid=1,iface=MIXER,name='PCM Playback Volume'
numid=5,iface=PCM,name='IEC958 Playback Con Mask'
numid=4,iface=PCM,name='IEC958 Playback Default'
But here I need knowledge about these particular numids for specific platform. On test x86 notebook list of amixer controls numids is significantly different. On notebook I do not see "PCM Playback Route" option.
So, is it possible to write general scripting solution which could work on different platforms? How to do this?