【发布时间】:2017-07-13 06:22:41
【问题描述】:
我想用我以编程方式给出的单词创建 mp3 文件。我正在使用 Google Text-To-Speech API 转换为 .mp3。代码工作正常,它也生成文件 test.mp3 但不是 .mp3 的原始格式(它看起来像一个 .mp3 文件,无法打开)。任何人都可以帮助我。 我的代码是:
var fs = require('fs');
var request = require('request');
var text = 'Hello World';
var options = {
url: 'http://translate.google.com/translate_tts?ie=UTF-8&q=' + encodeURIComponent(text) + '&tl=en&client=t',
headers: {
'Referer': 'http://translate.google.com/',
'User-Agent': 'stagefright/1.2 (Linux;Android 5.0)'
}
}
request(options)
.pipe(fs.createWriteStream('test.mp3'))
【问题讨论】:
-
请求带有这些特定标头的特定 URL 会产生 403(“禁止”)。看起来您也没有使用官方 API。
-
谢谢@ robertklep : 你能推荐一个正确的吗?
-
AFAIK 没有适用于 Google 的官方 TTS API。
标签: node.js google-translate google-text-to-speech