shichao-an / soundmeter

Simple real-time sound meter
https://soundmeter.shichao.io
BSD 2-Clause "Simplified" License
82 stars 27 forks source link

OSError: [Errno Input overflowed] #20

Closed janvda closed 6 years ago

janvda commented 6 years ago

I get the below error when running soundmeter on my raspberry pi. It doesn't take long to get the error (a few seconds up to a few minutes).

pi@pi3three:~ $ soundmeter Cannot connect to server socket err = No such file or directory Cannot connect to server request channel jack server is not running or cannot be started 123 Traceback (most recent call last): File "/usr/local/bin/soundmeter", line 11, in sys.exit(main()) File "/usr/local/lib/python3.4/dist-packages/soundmeter/meter.py", line 320, in main m.start() File "/usr/local/lib/python3.4/dist-packages/soundmeter/meter.py", line 122, in start record.send(True) # Record stream 'AUDIO_SEGMENT_LENGTH' long File "/usr/local/lib/python3.4/dist-packages/soundmeter/meter.py", line 94, in record data = self.stream.read(FRAMES_PER_BUFFER) File "/usr/lib/python3/dist-packages/pyaudio.py", line 605, in read return pa.read_stream(self._stream, num_frames) OSError: [Errno Input overflowed] -9981

janvda commented 6 years ago

I did some further research and it seems that my raspberry pi is not able to read the stream of audio quickly enough resulting in this buffer overflow exception.

https://people.csail.mit.edu/hubert/pyaudio/docs/#pyaudio.Stream.read

janvda commented 6 years ago

I fixed the issue by reducing the (sampling) rate from 44000 to 16000. This assured that my raspberry pi is able to keep up with the processing of the audio stream so that we no longer get this buffer overflow error.

I did this by creating a config file ~/.soundmeter/config with the following content (it is important that the rate is set to 16000 and not 44000)

[soundmeter]
frames_per_buffer = 2048
format = 8
channels = 2
rate = 16000
audio_segment_length = 0.5
rms_as_trigger_arg = False
ttfna commented 6 years ago

I have had the same issue on my raspberry pi that I could not fix by reducing the sampling rate or by increasing the frames_per_buffer value (which is suggested elsewhere).

However, setting exception_on_overflow=False (default is true)

https://people.csail.mit.edu/hubert/pyaudio/docs/#pyaudio.Stream.read

Has fixed it for me

ghost commented 6 years ago

How did you do that?

ttfna commented 6 years ago

you need to edit a line in pyaudio.py to read:

def read(self, num_frames, exception_on_overflow=False):

in my installation pyaudio.py is installed here:

/home/pi/.local/lib/python2.7/site-packages/pyaudio.py

and it is line 589

ghost commented 5 years ago

Thank you!!