我试图使用pyaudio以原始格式获取音频数据,然后在pocketsphinx中使用我的项目。但是,当我使用原始文件生成此程序的输出时,输出包含随机噪声。
我希望原始文件可以在pocketsphinx中使用。
import pyaudio
import wave
FORMAT = pyaudio.paInt32
CHANNELS = 1
RATE = 16000
CHUNK = 1024
RECORD_SECONDS = 2
audio = pyaudio.PyAudio()
# start Recording
stream = audio.open(format=FORMAT, channels=CHANNELS,
rate=RATE, input=True,
frames_per_buffer=CHUNK)
print "recording..."
frames = []
for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
data = stream.read(CHUNK)
frames.append(data)
print "finished recording"
# stop Recording
stream.stop_stream()
stream.close()
audio.terminate()
file = open("newfile.raw", "w")
file.write(b''.join(frames))
file.close()