Here is my code: import pyaudio tim=1 chunk = 8 FORMAT = pyaudio.paInt16 CHANNELS = 1 RATE = 50000 p = pyaudio.PyAudio() s = p.open(format = FORMAT,channels = CHANNELS,rate = RATE,input = True,output=True,frames_per_buffer = chunk) d=[] print((RATE // chunk) * tim) for i in range(0, (RATE // chunk * tim)): data = s.read(chunk) d.append(data) s.close() p.terminate()
There is no problem, but if I want to use the variable data during the loop for, I have this error: Traceback (most recent call last): File "<tmp 1>", line 14, in <module> data = s.read(chunk) File "c:\users\tissot\miniconda3\lib\site-packages\pyaudio.py", line 608, in read return pa.read_stream(self._stream, num_frames, exception_on_overflow) OSError: [Errno -9981] Input overflowed for example if i want to print data with this code: import pyaudio tim=1 chunk = 8 FORMAT = pyaudio.paInt16 CHANNELS = 1 RATE = 50000 p = pyaudio.PyAudio() s = p.open(format = FORMAT,channels = CHANNELS,rate = RATE,input = True,output=True,frames_per_buffer = chunk) d=[] print((RATE // chunk) * tim) for i in range(0, (RATE // chunk * tim)): data = s.read(chunk) d.append(data) print(data) # here is the problem s.close() p.terminate() In reality I would like to send it to my Arduino card as and when recording,(using: ser = serial.Serial('COM4', 115200) ser.write(data) ) but I have the same error as when I display it on the screen. If anyone knows an answer to this question, thank you in advance. -- https://mail.python.org/mailman/listinfo/python-list