Hi all. I am working on a project to playback and record audio at the same time via Python. To run these two functions simultaneously, I used the Threading function. My code are as seen below:
import threading
import time
def play1():
while time.time() < start_time:
pass
threading.Thread(target=playAudio).start()
def play2():
while time.time() < start_time:
pass
threading.Thread(target=recordAudio).start()
if __name__ == "__main__":
start_time=time.time()+1
threading.Thread(target=play1).start()
threading.Thread(target=play2).start()
However, when I ran the code I was met with the error as below:
Exception in thread Thread-4:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs)
File "/home/pi/0206.py", line 69, in recordAudio
data = stream.read(CHUNK)
File "build/bdist.linux-armv7l/egg/pyaudio.py", line 608, in read
return pa.read_stream(self._stream, num_frames, exception_on_overflow)
IOError: [Errno -9981] Input overflowed
KeyboardInterrupt
Can anyone kindly advise me on how to proceed from here or is there any other method to play/record simultaneously? Thanks in advance.