该楼层疑似违规已被系统折叠隐藏此楼查看此楼
我用Python库里的pyaudio录制语音 录制频率8000的语音会报错。
IOError: [Errno Invalid sample rate] -9997
录制频率48000的语音 正常录制
附上代码:
# -*- coding: utf-8 -*-
import pyaudio
import wave
import numpy as np
def Monitor():
CHUNK = 512
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 48000
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = "cache.wav"
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK)
print("开始缓存录音")
frames = []
while (True):
print 'begin '
for i in range(0, 100):
data = stream.read(CHUNK)
frames.append(data)
audio_data = np.fromstring(data, dtype=np.short)
large_sample_count = np.sum( audio_data > 800 )
temp = np.max(audio_data)
if temp > 800 :
print "检测到信号"
print '当前阈值:',temp
break
stream.stop_stream()
stream.close()
p.terminate()
wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
wf.setnchannels(CHANNELS)
wf.setsampwidth(p.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(b''.join(frames))
wf.close()
if __name__ == '__main__':
Monitor()
如果觉得《树莓派 python 录音_树莓派 录音问题》对你有帮助,请点赞、收藏,并留下你的观点哦!