问题:python在window上录多麦数据报错:python OSError: [Errno -9998] Invalid number of channels ? import pyaudio import wave CHUNK = 1024 FORMAT = pyaudio.paInt16 CHANNELS = 6 RATE = 16000 RECORD_SECONDS = 5 WAVE_OUTPUT_FILENAME = "record.wav" p = pyaudio.PyAudio() stream = p.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("* done recording") 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()
首先, 在网址:https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio找到对应的版本,下载下来,
然后,将python原有的pyaudio卸载掉,pip install PyAudio-0.2.11-cp36-cp36m-win_amd64.whl 即可。