BASE=/sys/class/sound if [ ! -d /sys/class/sound ]; then touch /tmp/noespeakup exit fi strip () { cardid=${1#$BASE/card} echo ${cardid%/id} } if ! grep -q speakup /proc/cmdline; then # Give drivers some time to detect boards :/ sleep 2 IDS=$(echo $BASE/card*/id) N=$(echo $IDS | wc -w) case $N in 0) touch /tmp/noespeakup exit ;; 1) # Just one card, can not be wrong /usr/bin/espeakup -V $(cat /tmp/speech) > /tmp/espeakup.log 2>&1 echo "/usr/bin/espeakup -V $(cat /tmp/speech)" >> /tmp/report ;; *) # Several cards, make the user choose CARD=none while [ "$CARD" = none ]; do for ID in $IDS; do i=$(strip $ID) ALSA_CARD=$(cat /sys/class/sound/card$i/id) ALSA_CARD=$ALSA_CARD /usr/bin/espeakup -V $(cat /tmp/speech) >> /tmp/espeakup.log 2>&1 echo "ALSA_CARD=$ALSA_CARD /usr/bin/espeakup -V $(cat /tmp/speech)" >> /tmp/report echo $ALSA_CARD >/tmp/alsacard echo "defaults.pcm.card $i" >/tmp/asound.conf echo "defaults.ctl.card $i" >>/tmp/asound.conf answer=none echo "Please type enter to use the sound board $ALSA_CARD" echo read -t 7 dummy answer=$? if [ $answer -eq 0 ]; then CARD=$i echo "Card chosen: $i" >> /tmp/cards break fi PID=$(ps -C espeakup --noheaders -o pid) kill -s 9 $PID sleep 1 done if [ "$CARD" = none ]; then echo "No card was selected. Speech will not be provided." touch /tmp/noespeakup rm /tmp/alsacard rm /tmp/asound.conf echo "No sound card selected" >> /tmp/report exit fi done esac fi