pythonpython-3.xamazon-web-servicestext-to-speechamazon-polly

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


I want to lower the speed at which the tts speaks at, I searched around for a couple of hours, but can't find the answer. Please help. Thank You in advance.


Solution

  • I got it, here is an example for all of those who don't get it either.

    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())