简体   繁体   English

Python,错误音频使用Pyaudio以16000Hz录音

[英]Python, Error audio Recording in 16000Hz using Pyaudio

I use Python 2.7.3, Mac OS 10.8.2 and Xcode 4.5.1 我使用Python 2.7.3,Mac OS 10.8.2和Xcode 4.5.1

I am trying to record sound using PyAudio following the instructions in http://people.csail.mit.edu/hubert/pyaudio/ 我试图按照http://people.csail.mit.edu/hubert/pyaudio/中的说明使用PyAudio录制声音

and using the program 并使用该程序

"""PyAudio example: Record a few seconds of audio and save to a WAVE file."""

import pyaudio
import wave

CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = "output.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()

It works well with RATE = 44100 . 它适用于RATE = 44100 But I want to record with RATE = 16000 and CHANNELS = 1 但我想记录RATE = 16000CHANNELS = 1

Changing the values give me an error as 更改值会给我一个错误 在此输入图像描述

How will I be able to record with RATE = 16000 ? 如何以RATE = 16000录制?

I experienced the same problem. 我遇到了同样的问题。 The issue was fixed in portaudio, but brew installed an old version for me. 问题已在portaudio中修复,但brew为我安装了旧版本。 I upgraded with 我升级了

brew install portaudio --HEAD

and then was able to run your code with CHANNELS=1 and RATE=16000 然后能够以CHANNELS = 1和RATE = 16000运行您的代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM