Using the Adafruit I2S MEMS microphone breakout board and the Raspberry Pi 2B, I am trying to read in stereo input using PyAudio and pass the data through a FFT to analyse. However I am not able to record the data from the microphone and plotting the data shows a high frequency square wave.
I have installed the I2S drivers according to the Adafruit website's tutorial https://learn.adafruit.com/adafruit-i2s-mems-microphone-breakout/ and I am able to record stereo audio using the following arcord command in terminal.
arecord -D plughw:1 -c2 -r 48000 -f S32_LE -t wav -V stereo -v file_stereo.wav
If anyone could help point me into the right direction that would be very helpful. Here is the code that I am using.
import pyaudio import numpy as np CHUNKSIZE = 1024 # fixed chunk size RATE = 44100 # initialize portaudio p = pyaudio.PyAudio() # Get input device number info = p.get_host_api_info_by_index(0) numdevices = info.get('deviceCount') for i in range(0, numdevices): if (p.get_device_info_by_host_api_device_index(0, i).get('maxInputChannels')) > 0: print "Input Device id ", i, " - ", p.get_device_info_by_host_api_device_index(0, i).get('name') stream = p.open(format=pyaudio.paInt16, channels=2, rate=RATE, input=True, frames_per_buffer=CHUNKSIZE, input_device_index = 2) # do this as long as you want fresh samples data = stream.read(CHUNKSIZE) numpydata = np.fromstring(data, dtype=np.int16) # close stream stream.stop_stream() stream.close() p.terminate() # Output as a WAV file import scipy.io.wavfile as wav wav.write('out.wav',RATE,numpydata)