本文介绍了使用NodeJ从Amazon Polly获取语音标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am working on an animation project to add subtitle to what my character says. I can get the mp3 file from AWS Polly with no issue.

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

However, when I want to get each part of the word separately, it doesn't work. I checked inspector tab, and I can see some params are passing to request to polly.aws. Any idea how I get json/mark-up file to know the start and end of each word & sentence?

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/

some useful links to check: https://aws.amazon.com/blogs/aws/new-amazon-polly-speech-marks/

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

using cli also works file: https://docs.aws.amazon.com/polly/latest/dg/speechmarkexamples.html but I want it in NodeJs

推荐答案

哦,我想我发现了一些东西:

Oh, I think I found something:

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

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

这篇关于使用NodeJ从Amazon Polly获取语音标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-02 14:27