1

我正在尝试让 AWS Polly 保存 URL 内容的 mp3 音频转录。我已经尝试了几个预先烘焙的脚本,但它们似乎都不起作用。

这是我的目标蓝图: (1) lambda 函数 - 调用 polly api StartSpeechSynthesisTask - 用作文本,URL 的内容 - 将音频文件保存在 s3

这是我在 Lambda 中尝试过的

var request = require("request");

request({uri: "https://www.canalmeio.com.br/ultima-edicao/"}, /*this is the URL where I pick up the text */
    function(error, response, body) {
    console.log(body);
  });
});

var params = {
  OutputFormat: mp3, 
  OutputS3BucketName: 'BUCKETNAMEXXXX'', 
  Text: console.log, 
  VoiceId: Cristiano, 
  Engine: standard,
  LanguageCode: pt-BR,
  OutputS3KeyPrefix: 'meio',
  SampleRate: '22050',
  TextType: text
};
polly.startSpeechSynthesisTask(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // successful response
});

我希望输出是保存在我的 s3 存储桶中的 MP3 文件。

4

1 回答 1

0

您好,欢迎来到 stackoverflow,

似乎您有一些语法错误(尤其是在 内部params)+您需要将 包装polly. startSpeechSynthesisTask在请求的回调中,因为您依赖于请求的响应。

根据您最初的帖子,我假设您正在使用 AWS Lambda。所以尝试以下

var request = require('request');

exports.handler = () => {
    request({ uri: 'https://www.canalmeio.com.br/ultima-edicao/' }, function (error, response, body) {
        var params = {
            OutputFormat: 'mp3',
            OutputS3BucketName: 'BUCKETNAMEXXXX',
            Text: body,
            VoiceId: 'Cristiano',
            Engine: 'standard',
            LanguageCode: 'pt-BR',
            OutputS3KeyPrefix: 'meio',
            SampleRate: '22050',
            TextType: 'text'
        };
        polly.startSpeechSynthesisTask(params, function (error) {
            if (error) {
                throw new Error(error);
            }
            return 'Success';
        });
    });
};

免责声明:它未经测试!

于 2019-08-28T07:41:42.233 回答