1

我正在使用 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!")
            })
        }
    }
})
4

3 回答 3

1

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

于 2018-02-12T16:33:53.030 回答
0

我认为您应该查看Amazon Polly 文档中关于SSML 标签的中断部分

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

编辑

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

文档说:

<speak>标签是所有 Amazon Polly SSML 文本的根元素。所有要朗读的 SSML 增强文本都必须包含在此标记中。

希望能帮助到你。

于 2018-02-12T16:01:38.837 回答
0

Amazon Polly 界面还提供 SSML - 以及纯文本(以及 C# 和 API 支持以及 CLI。)最简单的方法是在 SSML 窗口中键入内容,如下所示:

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>

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

于 2018-02-16T22:06:35.260 回答