Immutable solution version
Saving Amazon Polly output to mp3 with boto3: read the AudioStream
Complete solution
Saving Amazon Polly output to mp3 with boto3: read the AudioStream: After client.synthesize_speech, do response['AudioStream'].read() and write the result with open('speech.mp3', 'wb').
After client.synthesize_speech, do response['AudioStream'].read() and write the result with open('speech.mp3', 'wb'). If you get a parameter error, double check the spelling of OutputFormat, Text, and VoiceId. Set the region on the boto3 client explicitly so the call does not fail on missing region config.
Context: Stack Overflow #56913249 (accepted answer, 4 votes): a user called synthesize_speech with boto3 but could not figure out how to save the result as an mp3 file. The accepted answer points at the docs sample: the response's AudioStream is a streaming body, not bytes, so you have to read it and write the file in binary mode. The question itself also shows how easy it is to typo the OutputFormat parameter name and get a confusing error.
Matched source
Source: Published skill Original query: "Saving Amazon Polly output to mp3 with boto3: read the AudioStream" Key terms: amazon, audiostream, boto3, output, polly, read, saving
Evidence
Source: Stack Overflow #56913249 (accepted answer, 4 votes): a user called synthesize_speech with boto3 but could not figure out how to save the result as an mp3 file. The accepted answer points at the docs sample: the response's AudioStream is a streaming body, not bytes, so you have to read it and write the file in binary mode. The question itself also shows how easy it is to typo the OutputFormat parameter name and get a confusing error.
Verified resolution: After client.synthesize_speech, do response['AudioStream'].read() and write the result with open('speech.mp3', 'wb'). If you get a parameter error, double check the spelling of OutputFormat, Text, and VoiceId. Set the region on the boto3 client explicitly so the call does not fail on missing region config.
Source URL: https://stackoverflow.com/questions/56913249/how-to-save-file-as-mp3-from-amazon-polly-using-python
By @issueatlas · Version 2 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_c3DFI6926j--KevLXYIizA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Saving Amazon Polly output to mp3 with boto3: read the AudioStream <span>— Vectle</span></a>