Raspberry Pi – set sound interface shell script

Raspberry Pi
Raspberry Pi B © GijsbertPeijs/Flickr (CC BY 2.0)

 

For selecting the audio output I wrote a little script.

 

 

 

 

#!/bin/bash

if test $1  #check if parameter 1 / 0=auto, 1=analog, 2=hdmi is set
then

        echo "Try to select sound Interface:" $1
        sudo amixer cset numid=3  $1

else
        echo " select interface :" 
        echo "0=auto"
        echo "1=analog"
        echo "2=hdmi"
        read -p "Which interface should be used? " interfaceID
        echo "Try to select sound Interface:"  $interfaceID
        sudo amixer cset numid=3 interfaceID
fi