从Google翻译中提取音频

时间:2014-04-03 13:03:31

标签: translate

是否可以从Google翻译中提取音频?检查此链接,例如:

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

因此,如果你点击它,它会给你回复单词"选择"。有没有办法以某种形式的音频文件下载该语音?

由于

3 个答案:

答案 0 :(得分:0)

实际上我自己也在想这个,发现这个可以生成mp3文件的python脚本。

道具转到课程的原作者

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

答案 1 :(得分:0)

以下似乎有效(改编自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 :(得分:0)

您会发现,2014 年提到的解决方案不再有效,因为没有 mp3 文件作为响应,而是 base64 编码的音频。详情请看这里:

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

您可以获得一个简单的命令行界面,用于使用 tihs 项目提取/保存音频: https://github.com/Boudewijn26/gTTS(Google Text to Speech)

有了这个,你就可以做到:

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

并拥有您的音频文件。