This script uses the Google Translate text-to-speech service to render text as speech and play it back to the user. It supports a variety of languages (see README for a complete list), local audio caching, and 8, 12, 16, 32, 44.1, and 48 kHz output sample rates to match the channel's audio format.
This TTS service is unofficial and not supported by Google; it can be changed or terminated at any point without warning. People looking for TTS solutions to base their projects or products on should use an officially supported service.
perl : The Perl Programming Language
perl-libwww : The World-Wide Web library for Perl
perl-LWP-Protocol-https : For HTTPS support
HTTP::Tiny : Required by the tiny versions
sox : Sound eXchange, sound processing program
mpg123 : MPEG Audio Player and decoder
format_sln : Raw signed linear audio module for Asterisk
Internet access in order to contact Google and get the voice data.
The tiny AGI script requires MP3 format support in SoX, assumes SoX is installed at /usr/bin/sox, defaults to 8 kHz audio and SoX 14, and does not use mpg123. The tiny CLI script still requires mpg123.
To install, copy googletts.agi to your agi-bin directory.
The usual location is /var/lib/asterisk/agi-bin/.
Check /etc/asterisk/asterisk.conf for the configured directory.
agi(googletts.agi,"text",[language],[intkey],[speed]): This invokes the Google TTS engine, renders the text as speech, and plays it back to the user. If 'intkey' is set, the specified keys can interrupt playback. An interrupt key immediately terminates playback and causes the dialplan to proceed to the matching extension (for use in IVR). If 'speed' is set, the speech rate is altered by that factor (defaults to 1). The script contacts Google's TTS service and stores the resulting audio in a local cache (by default /tmp/) for future use. Default language, output sample rate, speed, caching, and cache directory settings can be changed by editing the variables near the top of the script.
Asterisk dialplan example:
;GoogleTTS Demo exten => 1234,1,Answer() ;;Play message in English: exten => 1234,n,agi(googletts.agi,"This is a simple Google text-to-speech test in English.",en) ;;Play message in Spanish: exten => 1234,n,agi(googletts.agi,"Esta es una simple prueba en español.",es) ;;Play message in Greek: exten => 1234,n,agi(googletts.agi,"Αυτό είναι ένα απλό τέστ στα ελληνικά.",el) ;;Play message in Japanese: exten => 1234,n,agi(googletts.agi,"これは、日本の簡単なテストです。良い一日を。",ja) ;;Play message in Simplified Chinese: exten => 1234,n,agi(googletts.agi,"这是一个简单的测试,在中国。有一个愉快的一天。",zh-CN)
;A simple dynamic IVR using GoogleTTS
[my_ivr]
exten => s,1,Answer()
exten => s,n,Set(TIMEOUT(digit)=5)
exten => s,n,agi(googletts.agi,"Welcome to my small interactive voice response menu.",en)
;;Wait for digit:
exten => s,n(start),agi(googletts.agi,"Please dial a digit.",en,any)
exten => s,n,WaitExten()
;;Play the name of the digit and wait for another one:
exten => _X,1,agi(googletts.agi,"You just pressed ${EXTEN}. Try another one please.",en,any)
exten => _X,n,WaitExten()
exten => i,1,agi(googletts.agi,"Invalid extension.",en)
exten => i,n,goto(s,start)
exten => t,1,agi(googletts.agi,"Request timed out.",en)
exten => t,n,goto(s,start)
exten => h,1,Hangup()
The GoogleTTS script for Asterisk is free software distributed under the GNU General Public License version 2.
Lefteris Zafiris (zaf@fastmail.com)
The latest source code is available in either ZIP or tar.gz format.
You can also clone the project with Git by running:
$ git clone https://github.com/zaf/asterisk-googletts.git
Speech recognition for
Asterisk
Text translation using Google Translate
API for Asterisk
Speech synthesis using Microsoft Translator
API for Asterisk
Asterisk Flite text-to-speech module
Asterisk eSpeak text-to-speech module