こちらの質問にあるように常時音を監視して一定異常の音量が鳴った回数を記録するプログラムとLEDの点灯を切り替えるプログラムをthreadingで並列処理させるプログラムを組んだのですが、並列処理はできているようなのデスがpyaudioでエラーが発生してしまいました。
Start Expression 'alsa_snd_pcm_mmap_begin( self->pcm, &areas, &self->offset, numFrames )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 3983 Expression 'PaAlsaStreamComponent_RegisterChannels( &self->capture, &self->bufferProcessor, &captureFrames, &xrun )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 4098 Expression 'PaAlsaStream_SetUpBuffers( stream, &framesGot, &xrun )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 4426 Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner self.run() File "/usr/lib/python2.7/threading.py", line 754, in run self.__target(*self.__args, **self.__kwargs) File "/home/pi/Desktop/py/final/judgeFunction.py", line 32, in judgeFunc data = stream.read(CHUNK) File "/usr/lib/python2.7/dist-packages/pyaudio.py", line 608, in read return pa.read_stream(self._stream, num_frames, exception_on_overflow) IOError: [Errno -9999] Unanticipated host error End
このstartとendはLEDの切り替えの合図です
コードと関数を記します
python
1import threading 2import elcFunc as ef 3import judgeFunction as jf 4 5if __name__ == "__main__": 6 thread1 = threading.Thread(target = jf.judgeFunc) 7 thread2 = threading.Thread(target = ef.noteStart) 8 9 thread2.start() 10 thread1.start() 11 12 jf.judgeEnd()
python
1def judgeFunc(): 2 while True: 3 global score 4 data = stream.read(CHUNK) 5 x = np.frombuffer(data, dtype="int16") / 32768.0 6 if x.max() > threshold: 7 score += 1 8 print(score)
python
1def noteStart(): 2 3 global a,i 4 initAll() 5 6 while a == True: 7 print("Start") 8 wiringpi.digitalWrite(GPIO26, LOW) 9 wiringpi.digitalWrite(GPIO21, LOW) 10 11 lf.noteLeft(random.randint(0, 15)) 12 suc = rf.noteRight(random.randint(0, 15)) 13 time.sleep(2) 14 15 while i < 28: 16 lf.noteLeft(suc) 17 suc = rf.noteRight(random.randint(0, 15)) 18 time.sleep(2) 19 i = i+1 20 21 wiringpi.digitalWrite(GPIO21, HIGH) 22 rf.endRight() 23 24 lf.noteLeft(suc) 25 time.sleep(2) 26 27 wiringpi.digitalWrite(GPIO26, HIGH) 28 lf.endLeft() 29 30 a = False
エラーコードで検索をかけても情報が少なく解決できませんでした。
分かる方回答の方よろしくお願いいたします。
追記
jf.judgeEnd関数です。
python
1def judgeEnd(): 2 stream.close() 3 p.terminate()
回答1件
あなたの回答
tips
プレビュー