午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

python - pyaudio stream.close()導(dǎo)致程序崩潰且不能捕獲到異常

瀏覽:222日期:2022-06-29 11:05:15

問(wèn)題描述

我想要頻繁地使用pyaudio來(lái)播放音頻,雖然他不是多線程模塊,但是只使用一個(gè)子線程播放,主線程控制播放的開(kāi)關(guān)應(yīng)該是沒(méi)有問(wèn)題的。但是當(dāng)我使用它播放時(shí)遇到了不能解決的麻煩。

import threadingimport waveimport pyaudioimport timepa=pyaudio.PyAudio()f=wave.open(’/home/dyan/catkin_ws/src/hlf_robot/scripts/hlf_voice/my.wav’,’rb’)raw_data=f.readframes(f.getnframes())f.close()samplewidth,channels,framerate,raw_data=2,1,16000,raw_datai=0stream1=’’def test(): while True:global i,pa,stream1try: print i stream1=pa.open(format=pa.get_format_from_width(samplewidth), channels=channels, rate=framerate, output=True) stream1.write(raw_data)i+=1 print iexcept IOError,e:print eexcept Exception,e:print ebreakt0=threading.Thread(target=test)t0.start()time.sleep(3)while True: if stream1.is_active():print 'is_active' else:print 'not active' if stream1.is_stopped():print 'is_stopped' else:print 'not stopped' print stream1._is_running print stream1._stream print ’123’ try:stream1.stop_stream()print ’456’stream1.close() except Exception,e:print ebreak print ’789’ time.sleep(3)

輸出是這樣的,然后崩了

0#子線程循環(huán)第一次is_active#not stopped #True #stream1._is_running<_portaudio.Stream object at 0x7efd71e00cb0> #stream1._stream123 #調(diào)用stop_stream()之前456 #調(diào)用stop_stream()之后,close()之前[Errno Unanticipated host error] -9999 #子線程捕獲到主線程調(diào)用stream1.stop_stream()時(shí)由stream1.write()拋出的異常IOError,忽略這個(gè)異常繼續(xù)執(zhí)行0#子線程stream1.write()拋出異常i+=1未執(zhí)行繼續(xù)循環(huán)在pa.open()之前的print

1、也就是說(shuō)在調(diào)用stream1.stop_stream()后調(diào)用stream1.close()導(dǎo)致程序崩潰了,而且子線程和主線程都沒(méi)有捕獲到異常!!!!2、如果將stop_stream()后的close()注釋掉短時(shí)間內(nèi)沒(méi)有任何問(wèn)題,但是持續(xù)運(yùn)行大約10分鐘左右雖然不會(huì)崩潰但是再也不能繼續(xù)播放。pa.open()一直拋出異常[Errno Illegal combination of I/O devices] -9993,當(dāng)我關(guān)閉程序重啟時(shí)pa.open()會(huì)拋出異常(’Invalid sample rate’, -9997),播放用不了了!!!

這個(gè)問(wèn)題該如何解決?

暫時(shí)使用每次播放均重開(kāi)一個(gè)pyaudio.Pyaudio()對(duì)象的方式解決,這大概額外使用了cpu時(shí)間10ms。持續(xù)跑了將近20個(gè)小時(shí)沒(méi)出問(wèn)題。

...try: self.pa=pyaudio.PyAudio()self.stream=self.pa.open(format=self.pa.get_format_from_width(samplewidth), channels=channels, rate=framerate, output=True) self.stream.write(raw_data)except IOError,e: passfinally: self.stream.close() self.pa.terminate()...

問(wèn)題解答

回答1:

這裡給了一個(gè)可能解決方法(workaround),ghost commented on 30 Jul 2016

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 欧美亚洲大片 | 亚洲一区天堂 | 啪视频在线观看 | 91免费福利视频 | 久久午夜伦理 | 久久免费小视频 | 天天草夜夜草 | 免费成人深夜 | 伊人网在线免费 | 日韩在线第二页 | 国产一级片免费观看 | 精品久久伊人 | 在线免费观看国产视频 | 亚洲在线天堂 | 久久亚洲综合色 | 中文字幕在线观看日韩 | 亚洲天堂成人 | 日本a大片 | 亚洲视频在线观看一区 | 色婷婷国产精品久久包臀 | 免费成人黄色网址 | 日韩欧美三级 | 亚洲欧美在线视频 | 五月天伊人网 | 国产欧美精品一区二区三区 | 中文字幕在线观看一区二区 | 另类欧美亚洲 | 韩国中文字幕hd久久精品 | 国产麻豆91 | 国产日韩欧美综合在线 | 91成人精品一区在线播放 | 国产精品1区2区3区4区 | 天天爽视频 | 国产黄色一级 | 精久久久久久久 | 午夜黄网| 三级国产在线观看 | 特黄视频免费看 | 国产一区二区三区四区视频 | 免费一级a毛片夜夜看 | 精品久久国产视频 |