Fork me on GitHub

Text to speech for asterisk using Google Translate

AGI script for the Asterisk open source PBX which allows you to use Googles' voice synthesis engine to render text to speech.

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-LWP-Protocol-https : For HTTPS support
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.

Asterisk dialplan example:

;GoogleTTS Demo

exten => 1234,1,Answer()
  ;;Play mesage 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()

        ;;PLayback 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()

License

The google TTS script for asterisk is free software distributed under the GNU General Public License version 2

Authors

Lefteris Zafiris (zaf@fastmail.com)

Download

The latest version is available in either zip or tar format.

You can also clone the project with Git by running:

$ git clone git://github.com/zaf/asterisk-googletts

Links

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 e-Speak text to speech module