【问题标题】:NODE Js: Wrong file type generating?NODE Js:生成错误的文件类型?
【发布时间】: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


【解决方案1】:

我得到了答案-

只需更改 url ,只需使用 +text+ 而不是 +encodeURIComponent(text)+

url: 'http://translate.google.com/translate_tts?ie=UTF-8&q=' + encodeURIComponent(text) + '&tl=en&client=t'

我不知道为什么encodeURIComponent() 不起作用。幸运的是现在修好了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-22
    • 2018-06-22
    • 2014-04-23
    • 2022-09-25
    • 2022-06-21
    相关资源
    最近更新 更多