| funasr/runtime/python/onnxruntime/demo_vad.py | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| funasr/runtime/python/onnxruntime/funasr_onnx/vad_bin.py | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
funasr/runtime/python/onnxruntime/demo_vad.py
@@ -1,12 +1,30 @@ import soundfile from funasr_onnx import Fsmn_vad model_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) 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) funasr/runtime/python/onnxruntime/funasr_onnx/vad_bin.py
@@ -53,13 +53,13 @@ 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 @@ 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_caches segments = self.vad_scorer(scores, waveform[0][None, :], is_final=is_final, max_end_sil=self.max_end_sil) except ONNXRuntimeError: