From d74b26a7e646963447c0d0b8774ddb04d7df9625 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sun, 15 Sep 2024 00:42:20 +0800 Subject: [PATCH] bugfix --- rtcllm/vad.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/rtcllm/vad.py b/rtcllm/vad.py index d6bc5eb..61269c4 100644 --- a/rtcllm/vad.py +++ b/rtcllm/vad.py @@ -139,11 +139,24 @@ class AudioTrackVad(MediaStreamTrack): return fs def frames_write_wave(self, frames): + """ fb = [ self.frame2bytes(f) for f in frames ] ndarr = np.frombuffer(b''.join(fb), dtype=np.int16) fn = temp_file(suffix='.wav') write(fn, frames[0].sample_rate, ndarr) return fn + """ + path = temp_file(suffix='.wav') + output_container = av.open(path, 'w') + out_stream = output_container.add_stream('pcm_s16le') + for frame in frames: + for packet in out_stream.encode(frame): + output_container.mux(packet) + for packet in out_stream.encode(None): + output_container.mux(packet) + output_container.close() + return path + async def write_wave(self): """Writes a .wav file. @@ -179,7 +192,7 @@ class AudioTrackVad(MediaStreamTrack): resampler = AudioResampler(format=out_stream.format, layout=out_stream.layout, rate=out_stream.rate) for frame in self.voiced_frames: for f in resampler.resample(frame): - output_container.mux(out_stream.encode(frame)) + output_container.mux(out_stream.encode(f)) output_container.mux(out_stream.encode()) output_container.close() return path