This commit is contained in:
yumoqing 2024-09-18 15:48:30 +08:00
parent 7000471bbe
commit e3322b9bac
2 changed files with 13 additions and 2 deletions

View File

@ -1,7 +1,7 @@
import pyaudio import pyaudio
import av import av
import numpy as np import numpy as np
from utils import frames_write_wave from vad import frames_write_wave
import sys import sys
import select import select
from vad import MyVad, bytes2frame, to16000_160_frames from vad import MyVad, bytes2frame, to16000_160_frames

View File

@ -12,7 +12,18 @@ from scipy.io.wavfile import write
import numpy as np import numpy as np
import av import av
from av import AudioLayout, AudioResampler, AudioFrame, AudioFormat from av import AudioLayout, AudioResampler, AudioFrame, AudioFormat
from utils import frames_write_wave
def frames_write_wave(frames):
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
def to16000_160_frames(frame): def to16000_160_frames(frame):
remind_byts = b'' remind_byts = b''