添加 1s 延迟到 Polly MP3 转换结束

Add 1s delay to end of Polly MP3 Conversion

我正在使用 Polly 生成文本到语音的 MP3 文件。我想在每个文件的末尾添加 1 秒的暂停。我该怎么做?

这是我正在处理的内容:

// Load the SDK
const AWS = require('aws-sdk')
const Fs = require('fs')
AWS.config.loadFromPath('config.json');

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

let params = {
    'Text': "This is the string I'm converting to MP3" ,
    'OutputFormat': 'mp3',
    'VoiceId': 'Kimberly'
}

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

我觉得你应该看看 break section on SSML Tags in Amazon Polly documentation

let params = {
    'Text': `
        This is the string I'm converting to MP3
        <break strength="medium"></break>
    ` ,
    'OutputFormat': 'mp3',
    'VoiceId': 'Kimberly'
};

编辑

也许您还必须将所有文本包含在 <speak> 标签中?

文档说:

The <speak> tag is the root element of all Amazon Polly SSML text. All SSML-enhanced text to be spoken must be included within this tag.

希望对您有所帮助。

看来我只需要添加 'TextType': 'ssml' 参数。此外,整个字符串需要包含在 <speak></speak> 标签中,中间有停顿。

Amazon Polly 界面还提供 SSML - 以及纯文本 (以及 C# 和 API 支持和 CLI。) 最简单的方法是在此处输入 SSML window:

一个1.7秒延迟的例子: <speak>This is the first episode in the MP3 AWS Architect. exam series. <break time="1.7s"/> EC two, exam tips, Part 1.</speak>

Five-second 间隙示例(四舍五入)同样有效: <speak>This is the second episode in the MP3 AWS Architect. exam series. <break time="5s"/> EC two, exam tips, Part 2.</speak>