Using Google Text to Speech with FreeSWITCH

Google Translate can be used as a  text-to-speech converter, providing a handy MP3 file of your chosen words. It's not an official offering, but Google Translate provides you the spoken version of your translation. There’s no official API for the text-to-speech service yet, but people around the web have figured out a way on using it.

One can get the speech audio as an MP3 file via a simple HTTP GET (REST) request:

"http://translate.google.com/translate_tts?tl=en&q=Venky+is+trying+Freeswitch”

 

Points to note here:

1. Just by changing the text in the above URL, after the 'q=' parameter, to whatever you want, will allow you’ll get back a MP3 file based on the text.

2. This is English only for now, and its limited to 100 characters.

3. This is not officially released by Google, so can be stopped/blocked anytime.

 

Now lets get to how we would use this with FreeSWITCH, to allow text to speech.

FreeSWITCH has a module to play audio from a streaming source - Mod_shout. We will be using this to get the job done.

 

Mod_shout can play remote mp3 files at any sample rate (8khz, 16khz, 44.5khz) in mono/stereo and re-sampling happens on the fly.

One could use this in one of the supported scripting languages like Lua, Javascript as below:



session.streamFile("shout://translate.google.com/translate_tts?tl=en&q=Venky+is+trying+Freeswitch", "")


 

or in a Dialplan like below for the extension 100:

 






<extension name="Google_TTS_FreeSWITCH">


 <condition field="destination_number" expression="^100$">


       <action application="answer" data=""/>


       <action application="playback" data="shout://translate.google.com/translate_tts?tl=en&q=Venky+is+trying+Freeswitch"/>


 </condition>


</extension>



 

Enjoy the free TTS experience!