0

i've got a problem with recording Audio over Pyaudio on a Raspberry Pi. The purpose of my code is to record small audio snippets, 10s long, every 10s to 20s.

To do this, I'm starting an own Thread for the recorder:

# Create collect beat thread.
recorder_thread = Thread(target=beat_analyzer, args=(recorder_queue,))
recorder_thread.start()

It uses another class to control the timing (recorder_queue). The recording itself happens in beat_analyzer. Somehow this is working fine for some time... but after about one hour or two, I get the following exception:

Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 505, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/home/pi/beatmap/bm-client/lib_recorder.py", line 134, in beat_analyzer
    py_audio.terminate()
  File "/usr/lib/pymodules/python2.7/pyaudio.py", line 644, in terminate
    for stream in self._streams:
RuntimeError: Set changed size during iteration

As I'm not iterating over something (at least I don't know about it) I wonder where the problem comes from. If it's perhaps something inside Pyaudio that I need to workaround? Hints much appreciated.

lightwaver
  • 31
  • 1
  • 6
  • Can you provide beat_analyzer and recorder_queue source and creation? Pastebin or Gist will do - I'd like to see what really happens, because your post is not informative yet. – Filip Malczak May 17 '15 at 09:50
  • Sure! Would be great if you can find something: http://pastebin.com/wecS8hcY – lightwaver May 17 '15 at 10:20
  • 1. Do you run only one thread with beat_analyzer or do you run many of them? 2. Change "except:" to "except BaseException as be:" and print that exception - something happens in "try" body that causes this specific situation, lets see what is it. – Filip Malczak May 17 '15 at 10:32
  • There are two complete separate threads. One is doing something with the LEDs and the other one is for the beat_analyzer. The threads are not stopped or anything. Both are started separated. I inserted the BaseException and it gives me following message: ('Input overflowed', -9981) – lightwaver May 17 '15 at 14:42
  • I found this here: https://www.raspberrypi.org/forums/viewtopic.php?f=32&t=97821 - so i altered my chunk size to CHUNK_COUNT = 8192. But that didn't solve the problem. Instead the error now occurs directly. So it seems to have something to do with the chunk size. – lightwaver May 17 '15 at 15:19
  • It's more like a bug of pyaudio not your code. – laike9m May 18 '15 at 07:32
  • Hmm... that's not good ;) Any ideas for a workaround? Perhaps suggestions for another lib? – lightwaver May 19 '15 at 07:38

1 Answers1

0

After a lot of experimenting with different chunk_count settings and also after reading laike9m's post I decided to use another library. In this case Alsaaudio - since then it works like a charme.

lightwaver
  • 31
  • 1
  • 6