我使用AWS-Lex生成对我的声音(http://boto3.readthedocs.io/en/latest/reference/services/lex-runtime.html)的响应。在
响应audioStream是boto3(https://botocore.readthedocs.io/en/latest/reference/response.html#botocore.response.StreamingBody)中的StreamingBody对象。在
问题是我能不能把一个字节转成数组?在
我试过以下方法:
audio_stream = response['audioStream'].read()
f = open('response.wav', 'wb')
f.write(audio_stream)
f.close()
但是我得到了一个错误,sox和aplay的格式是无效的(RIFF头没有找到)
我还尝试使用wave库,代码如下
^{pr2}$但是当我播放文件时,我只得到白噪音,而且长度很短。在
答案是在将流写入文件之前关闭流。工作代码如下:
相关问题 更多 >
编程相关推荐