Hi all,
First of all I should say that I'm quite new to Rasberry Pi and Python. I'm trying to write a Python script which will record audio using the element14 cirus logic board and pyaudio and then apply some signal processing algorithms. What I can't seem to understand is how to specify the Input for my data stream...Here's the code I'm using (for the moment I just want to write the data in a a test file)
import pyaudio CHUNK = 1024 FORMAT = pyaudio.paFloat32 CHANNELS = 1 RATE = 44100 RECORD_SECONDS = 5 OUTPUT_FILENAME = 'test' p = pyaudio.PyAudio() stream = p.open(format=FORMAT, channels=CHANNELS, rate=RATE, input=True, frames_per_buffer=CHUNK input_device_index = 2) print("* recording") frames = [] f = open(OUTPUT_FILENAME,'wb') runflag = 2 while runflag>0 data = stream.read(CHUNK) f.wite(data) time.sleep(.001) runflag = runflag-1 print("* done recording") stream.stop_stream() stream.close() p.terminate()
I tried different input_device_index when I open the stream but crashes all the time. However if I use input_device_index=2 it just blocks at stream.read(CHUNK) which I suppose happens because it doesn't get any input data.
Any help would be much appreciated!