This script makes use of Google's translate text to speech service in order to render text to speech and play it back to the user. It supports a variety of different languages (See README for a complete list), local caching of the voice data and also supports 8kHz or 16kHz sample rates to provide the best possible sound quality along with the use of wideband codecs.
This TTS service is 'unofficial' and not supported by Google, it can be terminated at any point with no warning. People looking for TTS solutions to base their projects/products on should look for alternative, officially supported services.
Dependencies
perl : The Perl Programming Language
perl-libwww : The World-Wide Web library for Perl
Perl-Crypt-SSLeay or perl-IO-Socket-SSL for SSL/TLS encryption
sox : Sound eXchange, sound processing program
mpg123 : MPEG Audio Player and decoder
format_sln : Raw slinear module for asterisk
Internet access in order to contact google and get the voice data.
Install
To install copy googletts.agi to your agi-bin directory.
Usually this is /var/lib/asterisk/agi-bin/
To make sure check your /etc/asterisk/asterisk.conf file.
Usage
agi(googletts.agi,text,[language],[intkey]): This will invoke the Google TTS engine, render the text string to speech and play it back to the user. If 'intkey' is set the script will wait for user input. Any given interrupt keys will cause the playback to immediately terminate and the dialplan to proceed to the matching extension (for use in IVR). The script contacts google's TTS service in order to get the voice data which then stores in a local cache (by default /tmp/) for future use. Parameters like default language, use of cache and cache dir can be set up by the user.
STEPS
yum install perl
yum install perl-libwww-perl
yum install sox
wget https://sourceforge.net/projects/mpg123/files/mpg123/1.25.8/mpg123-1.25.8.tar.bz2
tar xvjf mpg123-1.25.8.tar.bz2
cd mpg123-1.25.8
./configure
make
make install
ln -s /usr/local/bin/mpg123 /usr/bin/mpg123
Asterisk dialplan example:
exten => 1234,1,Answer()
;;Play mesage in Hindi:
exten => 1234,n,agi(googletts.agi,"विकास अच्छा लड़का है और मेरा नाम धूप है, मैं Google में काम नहीं करता",hi)
;;Play mesage in English:
exten => 1234,n,agi(googletts.agi,"This is a test working at all. I dont know thanks so much.",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)