pyaudio Is this a solution to: [Errno Input overflowed] -998
Posted: Mon Jul 01, 2013 12:36 pm
I have been trying to use pyaudio to listen for commands and there are lots of posts on this. My problem was that I continuously got the error IOError: [Errno Input overflowed] -9981. I am using a cheap logitech 3000 webcam directly connected to the USB. I stress that I am a complete novice with linux and python (having only started a couple of weeks ago with my Pi) so this may not be a solution, but if it helps someone all the better
Having all kinds of problems I eventually built a python script by copying [url]http://stackoverflow.com/questions/8921 ... python[url] and then adding some code to write the file. The trouble was I kept getting IOError: [Errno Input overflowed] -9981. I replaced the orginal code as follows
with
And changed the second parameter in the range by 1 until I got the error. I could get it to 4 but not 5
Here is the final result.
Not being able to get above 4, I then started playing with the RATE variable which did not make a difference (but some RATES such as 16000 produced an invalid frequency error.
I then tried the chunk variable firstly reducing it to 512 (didn't work) , and then doubling it to 2048. This seemed to work.
I then replaced the ammended code for the recording, as above, back to the original and tried recording times up to 30 seconds which seemed to work.
I hope that helps, no idea why this works.
Having all kinds of problems I eventually built a python script by copying [url]http://stackoverflow.com/questions/8921 ... python[url] and then adding some code to write the file. The trouble was I kept getting IOError: [Errno Input overflowed] -9981. I replaced the orginal code as follows
Code: Select all
for i in range(0, RATE / chunk * RECORD_SECONDS):
data = stream.read(chunk)
frames.append(data)
# check for silence here by comparing the level with 0 (or some threshold) for
# the contents of data.
# then write data or not to a fileCode: Select all
for i in range(0, 1):
data = stream.read(chunk)
frames.append(data)Here is the final result.
Code: Select all
# main recording logic from http://stackoverflow.com/questions/892199/detect-record-audio-in-python
import pyaudio
import sys
import wave
chunk = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 22050 #44100 might work also but not tested
RECORD_SECONDS = 10
WAVE_OUTPUT_FILENAME = "output.wav"
p = pyaudio.PyAudio()
frames = []
stream = p.open(format = FORMAT,
channels = CHANNELS,
rate = RATE,
input = True,
frames_per_buffer = chunk)
print "* recording"
for i in range(0, 4):
data = stream.read(chunk)
frames.append(data)
print "* done"
stream.stop_stream()
stream.close()
p.terminate()
wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
wf.setnchannels(CHANNELS)
wf.setsampwidth(p.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(b''.join(frames))
wf.close()I then tried the chunk variable firstly reducing it to 512 (didn't work) , and then doubling it to 2048. This seemed to work.
I then replaced the ammended code for the recording, as above, back to the original and tried recording times up to 30 seconds which seemed to work.
I hope that helps, no idea why this works.