Adding Text to Speech in HAMVoIP

Adding voice prompts to your AllStarLink node is a good way to make it more user friendly and provide periodic announcements.

I am always testing on my node and I have found that I use parrot mode a lot. The thing that has always bugged me is that there is not much feedback when you enable or disable parrot mode. Wouldn’t it be nice if they system told you. This is one example of using Text to Speech and creating a new voice prompt ot make the system more user friendly.

There are scripts already build into HAMVoIP to make this easier. There are many ways to implement Text to Speech but the built in scrips use an online service called voicerss.com. The service is free (for low use) so their is no cost but it does mean you will have ot sign up for an account and get your API Key.

Configuring the TTS script

Once you have your API key and your account is enabled, you can then configure the voice scrips in HAMVoIP. Login in to your HAMVoIP server and enter the bash shell (9 from the menu). Edit the file /usr/local/etc/tts.conf and add in your API Key.

# nano /usr/local/etc/tts.conf
tts_key=123ada45f4389d0453cde4732f23c5
tts_r=-1
tts_hl=en-us
tts_f=44khz_16bit_mono

Once you have aded your API key into the file, go ahead and save it.

Now you are all done and great to start generating speech.

Creating Audio from Text

Create a text file with the speech you want and place it in /etc/asterisk/local. For my use, I am going to create a file called parrot_mode_enabled.txt and put the string “Parrot Mode Enabled” it in.

# cd /etc/asterisk/local
# echo "Parrot Mode Enabled" > parrot_mode_enabled.txt

Then the next step is to run the script and convert it to audio.

# cd /etc/asterisk/local
# tts_audio.sh ./parrot_mode_enabled.txt

The script will now have completed the conversion and created files called parrot_mode_enabled.ul in the same directory.


Putting it All Together

Now that we have created the audio files for your node, we need to make it use them. I would like my node to tell the user when parrot mode is enabled or disabled. I think it is a lot more friendly than just the two beeps you normally hear. The way we will implement this is by creating a script that will get run from a DTMF function. The script will turn on/off parrot mode and announce to the user if it is on or off.

Creating the script

We are now going to create the shell script that will get run when ever a user turns off or on parrot mode. IN HAMVoIP, we will create the script in /usr/local/sbin and call it control_parrot.sh

NOTE: Running script this way does not work the same in ASL3 as ASL3 has changed the user rights when running scripts. This article is only works for HAMVoIP.

Login to the bash shell on your node and change directory to /usr/local/sbin

# cd /usr/local/sbin

Create a new file called control_parrot.sh and copy the following into it.

#!/bin/bash
#
# parrot_enable.sh  <node> <enable|disable>
# Enable Parrot mode and say if it is.
# Node is required
#


if [ -z "$1" ]
  then
    echo "No node number supplied - parrot_enable.sh <node> "
    exit 1
fi


# Check to see if parrot mode should be enabled.
# The default is to turn off parrot mode.  
case ${2} in
[Ee][Nn][Aa][Bb][Ll][Ee])
    asterisk -rx "rpt localplay ${1} /etc/asterisk/local/parrot_mode_enabled"
    sleep 2
    asterisk -rx "rpt cmd ${1} cop 21"
    ;;
*)
    asterisk -rx "rpt localplay ${1} /etc/asterisk/local/parrot_mode_disabled"
    sleep 2
    asterisk -rx "rpt cmd ${1} cop 22"
esac

Then change the permissions so it will run when called from your node.

# cd /usr/local/sbin
# chmod u+x,g+x control_parrot.sh

Adding the DTMF command into the Node

The final part is to add in the DTMF commands into your node so that when a user enters the correct DTMF tones it will run the script you just created. On my node, I have *840 setup to enable parrot mode and *841 to disable it. You can choose any DTMF sequence you want but make sure it doesn’t conflict with something you already have.

NOTE on DTMF Commands: AllStarNodes will watch for DTMF as it is entered and run the function or command as soon as it makes a match. If you have one command setup for *84 and another setup for *841, the last one will never get run since the node wil lalways match *84 first. Something to be aware of when planning you DTMF controls.

Login to your bash shell on your node and edit the file /etc/asterisk/rtp.conf file.

# cd /etc/asterisk
# nano rpt.conf

Scroll down to the stanza that starts with functions and your node number. For example ny node number is 60550 so look for the line (more than 2/3 down the file) that starts with [functions60550]. Under that line, insert the following two lines, make sure to change my node number 60550 to your node number. You can also change the 840 and 841 numbers at the start of the lines to what ever you wish for the DTMF sequence to enable or disable parrot mode on your node.

840=cmd,/usr/local/sbin/control_parrot.sh 60550 enable
841=cmd,/usr/local/sbin/control_parrot.sh 60550 disable

Save the file and restart Asterisk on your node.

astres.sh

Now you are done. Go ahead and give it is try. You should now hear your node announce the mode parrot is in when your enable or disable it.

Leave a Comment

Your email address will not be published. Required fields are marked *