如何改变 amazon polly 中的语速 (python)

How to change the speed of speech in amazon polly (python)

我想降低tts说话的速度,我搜索了几个小时,但找不到答案。请帮忙。提前谢谢你。

来自Voice Speed - Amazon Polly

Amazon Polly helps you slow down the rate of speech using the SSML tag, as in:

<speak>
     In some cases, it might help your audience to <prosody rate="85%">slow 
     the speaking rate slightly to aid in comprehension.</prosody>
</speak>

or

<speak>
     In some cases, it might help your audience to <prosody rate="slow">slow 
     the speaking rate slightly to aid in comprehension.</prosody>
</speak>

Python可以使用boto3 AWS SDK,它有一个synthesize_speech() API call that accepts a Text field with the text to convert into speech. If you also set TextType='ssml', then the text can include SSML,如上例所示。

我明白了,这里是所有不明白的人的例子。

import boto3

polly_client = boto3.Session(
               aws_access_key_id='your_access_key_id',
               aws_secret_access_key='your_secret_access_key',
               region_name='your_region').client('polly')


response = polly_client.synthesize_speech(
               VoiceId='Joanna',
               OutputFormat='mp3',
               Engine = 'neural', 
               TextType = "ssml", 
               Text = "<speak><prosody rate='90%'>The Quick Brown Fox Jumps Over the Lazy Dog</prosody></speak>") # prosody rate changes the speed of the speech.

with open('folder/speech.mp3', 'wb') as file: #the folder part is here if you want to create the mp3 in a specific folder, if you don't want that, just remove it.
   file.write(response['AudioStream'].read())