Record Audio Channels seperately

Hi, I have recently bought an Re-speaker Mic array v2.0 and installed 6-channel firmware. I would like to know how to record each channel separately(Especially channel0 which has processed audio for ASR). A python implementation would be great!!

Hi there,



here is the python example, <LINK_TEXT text=“http://wiki.seeedstudio.com/ReSpeaker_M … ract-voice”>http://wiki.seeedstudio.com/ReSpeaker_Mic_Array_v2.0/#extract-voice</LINK_TEXT> thanks.

Thanks for your reply. I already went through that link but didn’t help my scenario. But I was finally able to solve my issue :slight_smile:

hi

how to record channel seperately? the python example only show record all channels

Hi there,



Here is the code and configure the channel. thanks.



# deinterleave, select 1 channel

channel0 = data_array[0:]

#channel1 = data_array[1:]



# convert numpy array to string

data = channel0.tostring()

frames.append(data)




[code]import sys
import pyaudio
import wave
import numpy as np

CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 6
RATE = 16000
RECORD_SECONDS = 5

pyaudio_instance = pyaudio.PyAudio()

find the index of respeaker usb device

def find_device_index():
found = -1

for i in range(pyaudio_instance.get_device_count()):
    dev = pyaudio_instance.get_device_info_by_index(i)
    name = dev['name'].encode('utf-8')
    print(i, name, dev['maxInputChannels'], dev['maxOutputChannels'])
    if name.lower().find(b'respeaker') >= 0 and dev['maxInputChannels'] > 0:
        found = i
        break

return found

device_index = find_device_index()
if device_index < 0:
print(‘No ReSpeaker USB device found’)
sys.exit(1)

stream = pyaudio_instance.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
input_device_index=device_index,
frames_per_buffer=CHUNK)

print("* recording")

frames = []

for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
data = stream.read(CHUNK)

# convert string to numpy array
data_array = np.fromstring(data, dtype='int16')

# deinterleave, select 1 channel
channel0 = data_array[0:]
#channel1 = data_array[1:]

# convert numpy array to string 
data = channel0.tostring()
frames.append(data)

print("* done recording")

stream.stop_stream()
stream.close()
pyaudio_instance.terminate()

wf = wave.open(‘out.wav’, ‘wb’)
wf.setnchannels(1)
wf.setsampwidth(pyaudio_instance.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(b’’.join(frames))
wf.close()[/code]