我已经成功编写了一段代码,它将记录几秒钟的音频,并使用 pyaudio 将其保存在 python 2.7 中的选定目录中,如下所示:
import pyaudio
import wave
import sys
chunk = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = "%d_%d.wav" % (self.get('subject_nr'), self.get('count_inline_script'))
p = pyaudio.PyAudio()
stream = p.open(format = FORMAT,
channels = CHANNELS,
rate = RATE,
input = True,
frames_per_buffer = chunk)
现在,我最近才开始使用 Python 3.2,我想知道是否有办法像旧版本一样录制声音?