BASH   13

speaktext

Guest on 25th July 2022 05:06:59 AM

  1. #!/bin/bash
  2.  
  3. #
  4. # Script to speak letters and numbers from asterisk sounds
  5. # over a radio node using simpleusb
  6. # by Ramon Gonzalez KP4TR
  7. #
  8.  
  9. #set -xv
  10.  
  11. ASTERISKSND=/var/lib/asterisk/sounds
  12. LOCALSND=/tmp/randommsg
  13.  
  14.  
  15. function speak {
  16.         SPEAKTEXT=$(echo "$1" | tr '[:upper:]' '[:lower:]')
  17.         let SPEAKLEN=$(echo "$SPEAKTEXT" | /usr/bin/wc -m)-1
  18.         COUNTER=0
  19.         rm -f ${LOCALSND}.gsm
  20.         touch ${LOCALSND}.gsm
  21.         while [  $COUNTER -lt $SPEAKLEN ]; do
  22.                 let COUNTER=COUNTER+1
  23.                 CH=$(echo "$SPEAKTEXT"|cut -c${COUNTER})
  24.                 if [[ $CH =~ ^[A-Za-z_]+$ ]]; then
  25.                         cat ${ASTERISKSND}/letters/${CH}.gsm >> ${LOCALSND}.gsm
  26.                 fi
  27.                 if [[ ${CH} =~ ^-?[0-9]+$ ]]; then
  28.                         cat /var/lib/asterisk/sounds/digits/${CH}.gsm >> ${LOCALSND}.gsm
  29.                 fi
  30.  
  31.                 case $CH in
  32.                 .) cat ${ASTERISKSND}/letters/dot.gsm >> ${LOCALSND}.gsm;;
  33.                 -) cat ${ASTERISKSND}/letters/dash.gsm >> ${LOCALSND}.gsm;;
  34.                 =) cat ${ASTERISKSND}/letters/equals.gsm >> ${LOCALSND}.gsm;;
  35.                 /) cat ${ASTERISKSND}/letters/slash.gsm >> ${LOCALSND}.gsm;;
  36.                 !) cat ${ASTERISKSND}/letters/exclaimation-point.gsm >> ${LOCALSND}.gsm;;
  37.                 @) cat ${ASTERISKSND}letters/at.gsm >> ${LOCALSND}.gsm;;
  38.                 $) cat ${ASTERISKSND}/letters/dollar.gsm >> ${LOCALSND}.gsm;;
  39.                 *) ;;
  40.                 esac
  41.         done
  42.  
  43.         asterisk -rx "rpt localplay $2 ${LOCALSND}"
  44. }
  45.  
  46. if [ "$1" == "" -o "$2" == "" ];then
  47.         echo "Usage: speaktext.sh \"abc123\" node#"
  48.         exit
  49. fi
  50.  
  51. speak "$1" $2

Raw Paste


Login or Register to edit or fork this paste. It's free.