读取.wav文件而不是麦克风输入流

时间:2018-09-06 07:35:03

标签: numpy pyaudio wave

我一直在尝试修改this项目的解码器部分,以从.wav文件中读取而不是从麦克风输入流中读取,但到目前为止没有成功。

我要提到原始项目有效。

Decoder.py代表原始文件listen.py

的更改代码

原始版本:(来自 listen.py

def callback(in_data, frame_count, time_info, status):
    print(type(in_data))
    frames = list(quietnet.chunks(quietnet.unpack(in_data), chunk))
    for frame in frames:
        if not in_frames.full():
            in_frames.put(frame, False)
    return (in_data, pyaudio.paContinue)

p = pyaudio.PyAudio()
stream = p.open(format=FORMAT, channels=options.channels, rate=options.rate,
        input=True, frames_per_buffer=frames_per_buffer, stream_callback=callback)

我的版本:(来自 decoder.py

def readFileData(data):
    frames = list(quietnet.chunks(quietnet.unpack(data), chunk)) #unpacks bytes to frames
    for frame in frames:
        if not in_frames.full(): # check if element can be added to queue
            in_frames.put(frame, False)

wf = wave.open(filename, 'rb')
data = wf.readframes(chunk)
while len(data) > 0:
    readFileData(data)
    data = wf.readframes(chunk) # returns bytes like object
wf.close()

0 个答案:

没有答案