silero-vad
silero-vad copied to clipboard
Why shouldn't ONNX be set to True?
import os
import wave
import torch
import pyaudio
torch.set_num_threads(1)
os.environ['KMP_DUPLICATE_LIB_OK'] = 'True'
def record_audio_with_vad(file_path, vad_model, vad_utils, sample_rate=16000, chunk_size=512):
p = pyaudio.PyAudio()
stream = p.open(format=pyaudio.paInt16,
channels=1,
rate=sample_rate,
input=True,
frames_per_buffer=chunk_size)
data = stream.read(chunk_size)
frames = []
frames.append(data)
with wave.open(file_path, 'wb') as wf:
wf.setnchannels(1)
wf.setsampwidth(pyaudio.PyAudio().get_sample_size(pyaudio.paInt16))
wf.setframerate(sample_rate)
wf.writeframes(b''.join(frames))
frames = []
(get_speech_timestamps,
save_audio,
read_audio,
VADIterator,
collect_chunks) = vad_utils
wav = read_audio(file_path, sampling_rate=sample_rate)
test = vad_model.audio_forward(wav, 16000)
if __name__ == "__main__":
USE_ONNX = True
vad_model, vad_utils = torch.hub.load(repo_or_dir='snakers4/silero-vad',
model='silero_vad',
force_reload=True,
onnx=USE_ONNX)
output_file = "C:/Users/ISPL/PycharmProjects/ASR/sample/test.wav" # Change the filename as needed
a = 0
while a == 0:
try:
record_audio_with_vad(output_file, vad_model, vad_utils)
except KeyboardInterrupt:
a = 1
break
When I set ONNX to False, it works fine. However, when I set it to True, the following error appears.
onnxruntime.capi.onnxruntime_pybind11_state.InvalidArgument: [ONNXRuntimeError] : 2 : INVALID_ARGUMENT : Unexpected input data type. Actual: (tensor(int32)) , expected: (tensor(int64))