如何从 Google Coral Dev board ( mini ) 上的 PDM 麦克风获取声音?

问题描述

我刚刚接触了令人惊叹的 Google Coral 开发板,但我缺乏足够的教程或软件生态系统。我查看了数据表,发现板上有一个 PDM 麦克风。我的问题是,我怎样才能从它录制声音?是否有任何本机应用程序,我可以从 python 中做到这一点吗?谢谢

解决方法

我能够通过 pyaudio 让它运行

import pyaudio
import wave

# the file name output you want to record into
filename = "recorded.wav"
# set the chunk size of 1024 samples
chunk = 1024
# sample format
FORMAT = pyaudio.paInt16
# mono,change to 2 if you want stereo
channels = 1
# 44100 samples per second
sample_rate = 44100
record_seconds = 5
# initialize PyAudio object
p = pyaudio.PyAudio()
# open stream object as input & output
stream = p.open(format=FORMAT,channels=channels,rate=sample_rate,input=True,output=True,frames_per_buffer=chunk)
frames = []
print("Recording...")
for i in range(int(44100 / chunk * record_seconds)):
    data = stream.read(chunk)
    frames.append(data)
print("Finished recording.")
# stop and close stream
stream.stop_stream()
stream.close()
# terminate pyaudio object
p.terminate()
# save audio file
# open the file in 'write bytes' mode
wf = wave.open(filename,"wb")
# set the channels
wf.setnchannels(channels)
# set the sample format
wf.setsampwidth(p.get_sample_size(FORMAT))
# set the sample rate
wf.setframerate(sample_rate)
# write the frames as bytes
wf.writeframes(b"".join(frames))
# close the file
wf.close()


或者如@Manoj所说,可以使用arecord本机应用程序