Closed lvignals closed 4 years ago
@lvignals - Thank you for your post. I am not able to reproduce the issue. Can you please run this code and provide me debug log ?
import boto3
polly = boto3.client('polly')
boto3.set_stream_logger('')
response = polly.synthesize_speech(Text="Hello world!", OutputFormat="mp3", VoiceId="Joanna")
with closing(response["AudioStream"]) as stream:
with open('polly.mp3', "wb") as fp:
fp.write(stream.read())
Once the stream is read it will be closed. So please make sure you are not using same response stream twice.
Actually I had found the issue, the construct that causes the empty file is caused by that line: with closing(response["AudioStream"]) as stream: changing to with response["AudioStream"] as stream: and closing after (outside) the With statement gave me a complete audio file instead of a 0 byte file. I understand the reasoning behind using with closing(...)but it is not a reliable construct apparently. All the best and thank you for the reply. LV
On Wednesday, May 6, 2020, 04:21:28 PM PDT, swetashre <notifications@github.com> wrote:
@lvignals - Thank you for your post. I am not able to reproduce the issue. Can you please run this code and provide me debug log ? import boto3
polly = boto3.client('polly')
boto3.set_stream_logger('')
response = polly.synthesize_speech(Text="Hello world!", OutputFormat="mp3", VoiceId="Joanna")
with closing(response["AudioStream"]) as stream: with open('polly.mp3', "wb") as fp: fp.write(stream.read()) Once the stream is read it will be closed. So please make sure you are not using same response stream twice.
— You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Boto3 + Polly, silent failure without error · Issue #2413 · boto/boto3
When using Boto3 to access Polly in the script below: Script runs without error but creates an empty .mp3 file. ... |
|
|
|
Build software better, together
GitHub is where people build software. More than 50 million people use GitHub to discover, fork, and contribute ... |
|
|
I am glad you got it working. Closing this issue as it has been resolved. Please reopen if you have more concerns.
When using Boto3 to access Polly in the script below:
Code is as follow and taken from AWS website samples: