如何在boto3中使用AWS polly进行暂停

How to use AWS polly in boto3 for pause

我的代码如下:

import boto3
polly_client = boto3.Session().client('polly')    

response = polly_client.synthesize_speech(
    VoiceId='Joanna',
    OutputFormat='mp3', 
    Text = sentence
)
audio = response['AudioStream']

我试过使用下面的句子:

sentence = '''<speak><s>Mary had a little lamb</s> <s>Whose fleece was white as snow</s>And everywhere that Mary went, the lamb was sure to go.</speak>'''

但是生成的音频没有停顿,它只是读出文本。

这会为短语“Hello world”生成一个音频文件,在单词之间停顿 2 秒:

import boto3
polly_client = boto3.Session().client('polly')

sentence = '''<speak>Hello <break time='2000ms'/> World</speak>'''

response = polly_client.synthesize_speech(
    VoiceId='Joanna',
    OutputFormat='mp3',
    TextType='ssml',
    Text=sentence
)

file = open('speech.mp3', 'wb')
file.write(response['AudioStream'].read())
file.close()

有关详细信息,请参阅 Using SSML 下的 aws 文档小节。