Adding Text to Speech in ASL3

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.

The Audio Files

Asterisk that is built into ASL3 can play a number of different types of audio files. The best format for ASL3 is ulaw audio. ASL3 doesn’t currently have a utility built in for converting text to speech but there is a good utility you can install. See my article here for how to install it. For now I will assume you already have the audio files that will do your announcements.

Adding the Audio Files

Create a directory that the asterisk user can access. For me, I create a local directory under my /etc/asterisk directory so all the files are together and easy for the backups.

Login to your node and enter the terminal

# mkdir -p /etc/asterisk/local
# cd /etc/asterisk
# mkdir local
# chown asterisk:asterisk local

Copy two audio files over and place them into the /etc/asterisk/local. I called my two audio files parrot_mode_enabled.ui and parrot_mode_disabled.ui. After you have copied over the file, make sure to change the ownership of the files so that asterisk can ready them.

# cd /etc/asterisk/local
# chown asterisk:asterisk parrot_mode*

Putting it All Together

Now that we have 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 ASL3, we will create the script in /etc/asterisk/local and call it control_parrot.sh

NOTE: ASL3 has changed the way asterisk is run. It now runs as the user asterisk so we have to make sure the file can be run by htat user.

Login to the bash shell on your node and change directory to /etc/asterisk/local

# cd /etc/asterisk/local

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 0"
    ;;
*)
    asterisk -rx "rpt localplay ${1} /etc/asterisk/local/parrot_mode_disabled"
    sleep 2
    asterisk -rx "rpt cmd ${1} cop 22 0"
esac

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

# cd /etc/asterisk/local
# chown asterisk:asterisk control_parrot.sh
# 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] . 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 you enable or disable it.

Leave a Comment

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