擅长:python、mysql、java
<p>在我的例子中,我解决了在关闭流之前添加暂停的问题。不确定这是否是预期行为,但我的嵌入式设备上的音频在写入流后以异步方式播放。所以我不得不在关闭溪流之前等待。我完成的设置是这样的:</p>
<pre><code>import time
...
#calculate clip duration in seconds
duration = float(clip_data_length) / rate / bytes_per_sample / channels
startTime = time.time()
stream.write(wav_data)
endTime = time.time()
if ((endTime - startTime) < duration):
time.sleep(duration - (endTime - startTime))
time.sleep(0.1)
stream.close()
</code></pre>