[英]Pyaudio recording wav file with soundcard gives an empty recording
我一直在尝试一个项目,以检测两个流音频信号之间的时间偏移。 我使用python3,Pyaudio进行工作,并且我正在使用带有Neumann KU-100麦克风且带有立体声输入的Motux828声卡。 因此,当我检查我的input_device_index
我是正确的那是连接到MOTU声卡的第4个。
但是当我用以下方式记录时:
import time
import pyaudio
import wave
CHUNK = 1024 * 3 # Chunk is the bytes which are currently processed
FORMAT = pyaudio.paInt16
RATE = 44100
RECORD_SECONDS = 2
WAVE_OUTPUT = "temp.wav"
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT,channels=2,rate=RATE,input=True,frames_per_buffer=CHUNK,input_device_index=4)
frames = [] # np array storing all the data
for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
data = stream1.read(CHUNK)
frames.append(data1)
stream.stop_stream()
stream.close()
p.terminate()
wavef = wave.open(WAVE_OUTPUT, 'wb') # opening the file
wavef.setnchannels(1)
wavef.setsampwidth(p.get_sample_size(FORMAT))
wavef.setframerate(RATE)
wavef.writeframes(b''.join(frames1)) # writing the data to be saved
wavef.close()
我录制的波形文件没有声音,几乎没有噪音(自然)
我也可以使用特定麦克风使用第三方软件录制。 它完全可以正常工作。
注意: 声卡通常为24位深度,我也尝试使用paInt24
录制纯噪声的波形文件
我认为您在查看您的代码时提到了错误的变量名。 错误的变量是:
data = stream1.read(CHUNK)
frames.append(data1)
wavef.writeframes(b''.join(frames1))
正确的值是:
data = stream.read(CHUNK)
frames.append(data)
wavef.writeframes(b''.join(frames))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.