【问题标题】:Get speech mark from Amazon Polly using NodeJs使用 NodeJs 从 Amazon Polly 获取语音标记
【发布时间】:2019-07-13 19:55:19
【问题描述】:

我正在制作一个动画项目,为我的角色所说的内容添加字幕。我可以毫无问题地从 AWS Polly 获取 mp3 文件。

但是,当我想分别获取单词的每个部分时,它不起作用。我检查了检查器选项卡,我可以看到一些参数正在传递给 polly.aws 的请求。知道如何获取 json/mark-up 文件以了解每个单词和句子的开头和结尾吗?

const AWS = require('aws-sdk')
const Fs = require('fs')

const Polly = new AWS.Polly({
    signatureVersion: 'v4',
    region: 'us-east-1'
})

// # this part works fine
let params = {
    'Text': 'Hi, my name is Soley. We are building something amazing!',
    'OutputFormat': 'mp3',
    'VoiceId': 'Matthew'
}

// # from chrome's network tab:
// # and is there a way to get mp3 and mark-up text at the same time?
// "text": "Hi, my name is Soley. We are building something amazing!",
//     "textContentType": "text",
//     "voiceId": "Matthew",
//     "languageCode": "en-US",
//     "engine": "standard",
//     "outputFormat": "json-8000",
//     "lexiconNames": [],
//     "speechMarksTypes": [
//         "word",
//         "sentence"
//     ]

Polly.synthesizeSpeech(params, (err, data) => {
    if (err) {
        console.log(err)
    } else if (data) {
        console.log(data)
        if (data.AudioStream instanceof Buffer) {
            Fs.writeFile("speech."+params.OutputFormat, data.AudioStream, function (err) {
                if (err) {
                    return console.log(err)
                }
                console.log("The file was saved!")
            })
        }
    }
})

一些有用的链接检查:https://aws.amazon.com/blogs/aws/new-amazon-polly-speech-marks/

使用 cli 也可以使用文件:https://docs.aws.amazon.com/polly/latest/dg/speechmarkexamples.html 但我想在 NodeJs 中使用它

【问题讨论】:

    标签: amazon-web-services text-to-speech amazon-polly


    【解决方案1】:

    哦,我想我找到了一些东西:

    let params = {
        'Text': 'Hi, my name is Soley. We are building something amazing!',
        'OutputFormat': 'json',
        'VoiceId': 'Matthew',
        'SpeechMarkTypes': ['word', 'sentence']
    }
    

    感谢javahttps://docs.aws.amazon.com/polly/latest/dg/SynthesizeSpeechMarksSample.html

    【讨论】:

    • 天哪,谢谢,在从 application/x-json-stream Polly 回复中得到一个空字符串 2 小时后,我变得士气低落。我以为我的流保存代码以某种方式被破坏了。但事实证明我使用的是params.SpeechMarkType = "word"。也就是说,属性名称必须是复数,并且必须是一个数组。 Amazon Polly 真的应该回退到 SpeechMarkTypes 默认值,而不是返回无效的 JSON 字符串!
    猜你喜欢
    • 1970-01-01
    • 2013-11-14
    • 1970-01-01
    • 2019-04-26
    • 1970-01-01
    • 2019-03-08
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    相关资源
    最近更新 更多