Not sure if there has been any solution through python code thats been found.
But I was able to get it working by directly accessing the fifo socket of the channel in the mic array.
I tried with pyaudio but just couldn’t get it to work. This code snippet records on channel 8 for 10 seconds and saves the audio file as a .wav
You can replace channel 8 with your channel of interest.
CHUNK = 1024
FORMAT = 8
CHANNELS = 1
RATE = 16000 #sample rate
RECORD_SECONDS = 10
currentDir = "audio/"
if not os.path.exists(currentDir):
os.makedirs(currentDir)
clipFile = os.path.join(currentDir, "vallie" + "-" + time.strftime("%Y%m%d-%H%M%S") + ".wav")
print("* start recording")
frames = []
timeout = time.time() + RECORD_SECONDS + 1
while time.time() < timeout:
with open('/tmp/matrix_micarray_channel_8') as fifo:
print("FIFO opened")
while True:
data = fifo.read()
if len(data) == 0:
continue
frames.append(data)
break
print("* done recording")
wf = wave.open(clipFile, 'wb')
wf.setnchannels(CHANNELS)
wf.setsampwidth(2)
wf.setframerate(RATE)
wf.writeframes(b''.join(frames))
wf.close()