amazon-web-services - 使用 NodeJs 从 Amazon Polly 获取语音标记
问题描述
我正在做一个动画项目,为我的角色所说的内容添加字幕。我可以毫无问题地从 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 中使用它
解决方案
哦,我想我发现了一些东西:
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
推荐阅读
- ionic3 - 离子离线应用同步
- java - Android 应用程序在模拟器上运行良好,但在真实设备上却不行
- javascript - 通过 onClick 选择语言
- javascript - React Native - setState 在传递数据时未定义
- r - 如何使用R中的条件分隔变量中的级别
- matplotlib - 在 Google Colaboratory 上保存或下载 matplotlib 绘图图像
- logging - 以简洁的方式在 java8 Predicate 中记录条件结果
- ruby-on-rails - 页面更改时 Rails 应用程序中的视频/图像故障
- reactjs - 如何将UTC时间戳转换为本地浏览器时间
- json - 使用 fs.writeFileSync() 写入文件时附加匿名换行符