Open-source speech recognition toolkit for training, inference, streaming ASR, VAD, punctuation, speaker diarization pipelines, and OpenAI-compatible/MCP serving.
Python asraudiochineseemotion-recognitionfunasrmcp-servermultilingual-asropenai-compatible-apiparaformerpunctuationpytorchreal-time-asrspeaker-diarizationspeech-recognitionspeech-to-textstreaming-asrtranscriptionvllmvoice-activity-detectionwhisper-alternative
export
游雁c039cbc3bf33
diff --git a/funasr/runtime/python/onnxruntime/demo_vad.py b/funasr/runtime/python/onnxruntime/demo_vad.pyindex ae033cc5b..2e171978c 100644--- a/funasr/runtime/python/onnxruntime/demo_vad.py+++ b/funasr/runtime/python/onnxruntime/demo_vad.py@@ -1,12 +1,30 @@-+import soundfilefrom funasr_onnx import Fsmn_vadmodel_dir = "/Users/zhifu/Downloads/speech_fsmn_vad_zh-cn-16k-common-pytorch"-+wav_path = "/Users/zhifu/Downloads/speech_fsmn_vad_zh-cn-16k-common-pytorch/example/vad_example.wav"model = Fsmn_vad(model_dir)-wav_path = "/Users/zhifu/Downloads/speech_fsmn_vad_zh-cn-16k-common-pytorch/example/vad_example.wav"+#offline vad+# result = model(wav_path)+# print(result)++#online vad+speech, sample_rate = soundfile.read(wav_path)+speech_length = speech.shape[0]++sample_offset = 0+step = 160 * 10+param_dict = {'in_cache': []}+for sample_offset in range(0, speech_length, min(step, speech_length - sample_offset)):+ if sample_offset + step >= speech_length - 1:+ step = speech_length - sample_offset+ is_final = True+ else:+ is_final = False+ param_dict['is_final'] = is_final+ segments_result = model(audio_in=speech[sample_offset: sample_offset + step],+ param_dict=param_dict)+ print(segments_result)-result = model(wav_path)-print(result)\ No newline at end of filediff --git a/funasr/runtime/python/onnxruntime/funasr_onnx/vad_bin.py b/funasr/runtime/python/onnxruntime/funasr_onnx/vad_bin.pyindex 0b7ecffc0..cdd4578d1 100644--- a/funasr/runtime/python/onnxruntime/funasr_onnx/vad_bin.py+++ b/funasr/runtime/python/onnxruntime/funasr_onnx/vad_bin.py@@ -53,13 +53,13 @@ class Fsmn_vad():proj_dim = self.encoder_conf["proj_dim"]lorder = self.encoder_conf["lorder"]for i in range(fsmn_layers):- cache = np.zeros(1, proj_dim, lorder-1, 1).astype(np.float32)+ cache = np.zeros((1, proj_dim, lorder-1, 1)).astype(np.float32)in_cache.append(cache)return in_cache- def __call__(self, wav_content: Union[str, np.ndarray, List[str]], **kwargs) -> List:- waveform_list = self.load_data(wav_content, self.frontend.opts.frame_opts.samp_freq)+ def __call__(self, audio_in: Union[str, np.ndarray, List[str]], **kwargs) -> List:+ waveform_list = self.load_data(audio_in, self.frontend.opts.frame_opts.samp_freq)waveform_nums = len(waveform_list)is_final = kwargs.get('kwargs', False)@@ -70,13 +70,13 @@ class Fsmn_vad():waveform = waveform_list[beg_idx:end_idx]feats, feats_len = self.extract_feat(waveform)param_dict = kwargs.get('param_dict', dict())- in_cache = param_dict.get('cache', list())+ in_cache = param_dict.get('in_cache', list())in_cache = self.prepare_cache(in_cache)try:inputs = [feats]inputs.extend(in_cache)scores, out_caches = self.infer(inputs)- param_dict['cache'] = out_caches+ param_dict['in_cache'] = out_cachessegments = self.vad_scorer(scores, waveform[0][None, :], is_final=is_final, max_end_sil=self.max_end_sil)except ONNXRuntimeError: