1

Is it possible to extract the audio from the Google translate? check this link, for example:

http://translate.google.com/translate_tts?tl=en&q=%22choose%22

So if you click on this, it will give you back the word "choose". Is there a way to download that speech in some form of audio file?

Thanks

1

3 Answers 3

1

Actually was wondering about this myself, found this python script which can generate a mp3 file.

props go to original author ofcourse

https://github.com/hungtruong/Google-Translate-TTS/blob/master/GoogleTTS.py

1

The following seems to work (adapted from the link I posted above):

<?php
/**
* Initialize the cURL session
*/
$ch = curl_init();
/**
* Set the URL of the page or file to download.
*/
curl_setopt($ch, CURLOPT_URL,
'http://translate.google.com/translate_tts?tl=en&q=%22choose%22');
/**
* Create a new file
*/
$fp = fopen('audiofile', 'w');
/**
* Ask cURL to write the contents to a file
*/
curl_setopt($ch, CURLOPT_FILE, $fp);
/**
* Execute the cURL session
*/
curl_exec ($ch);
/**
* Close cURL session and file
*/
curl_close ($ch);
fclose($fp);
?>
2
  • Depends a bit on your environment. It is php code. You can run it on your machine (if you have php installed - which is true by default on Mac OS or Linux; if you run windows you need to work a little harder). On my Mac, I paste this code into a file called "getaudio.php", then from the command line I type php getaudio.php. A couple of seconds later, the file audiofile appears in my directory.
    – Floris
    Apr 3, 2014 at 14:12
  • Bottom line is this - you need to use a program that requests the file; python and php are the most commonly used languages to do that. If you are not familiar with either, then this is probably the wrong forum for asking your question - it may be that you are looking for a ready made tool (and that is explicitly not what this site is about - it is about writing programs).
    – Floris
    Apr 3, 2014 at 14:13
0

You will find, that the solutions mentioned in 2014 don’t work anymore, as there is no mp3 file as a response, but a base64 encoded audio. For details see here:

https://github.com/Boudewijn26/gTTS-token/blob/master/docs/november-2020-translate-changes.md

You can get a simple command line interface for extracting/saving the audio with tihs project: https://github.com/Boudewijn26/gTTS (Google Text to Speach)

With this you can just do:

gtts-cli 'hello' --output hello.mp3

and have your audio file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.