Download MP3 from Google Translate text to speech

user1169690 picture user1169690 · Feb 6, 2012 · Viewed 66.9k times · Source

I found this code from the Internet and it uses the Google translate's text to speech capability using URL. here is the code:

http://translate.google.com/translate_tts?tl=en&q="hello world"

I know how to call this in my vb.net but I don't know how to save the MP3 file from Google Translate. i used the system.speech in vb.net to have this capability but I specifically need to get the speech from google translate. so, does anyone know how to save the sound file from Google Translate using that URL? Thanks.

Answer

Bobble picture Bobble · Dec 11, 2012

EDIT 2015-12-26

As of 2015-12-21 this code no longer works following further changes to the Google TTS API. As indicated by @ncpierson a new additional parameter tk is required, and I am having a hard time working out how to calculate it in a shell script. I will revise this answer with a new edit as/when I can.

I'm not sure about Windows, but in Linux this is very easy from the command line. I use a command line script to download English audio of text strings:

#!/bin/bash
# write an English text string as an audio file using Google Translate
# usage: en2audio.sh <text>
wget -q -U Mozilla -O "$*.mp3" "http://translate.google.com/translate_tts?ie=UTF-8&client=t&tl=en&q=$*"

I do the same thing with Chinese (the script is a bit simpler because there are no spaces to parse between words):

#!/bin/bash
# write a Chinese text string as an audio file using Google Translate
# usage: zh2audio.sh <text>
wget -q -U Mozilla -O $1.mp3 "http://translate.google.com/translate_tts?ie=UTF-8&client=t&tl=zh&q=$1"

Most Linux distros include wget as standard, but it can easily be downloaded (see, e.g, this link).

(Thanks to @ncpierson for client=t parameter).