| | |
| | | device_id: Union[str, int] = "-1", |
| | | quantize: bool = False, |
| | | intra_op_num_threads: int = 4, |
| | | max_end_sil: int = 800, |
| | | max_end_sil: int = None, |
| | | ): |
| | | |
| | | if not Path(model_dir).exists(): |
| | |
| | | self.ort_infer = OrtInferSession(model_file, device_id, intra_op_num_threads=intra_op_num_threads) |
| | | self.batch_size = batch_size |
| | | self.vad_scorer = E2EVadModel(config["vad_post_conf"]) |
| | | self.max_end_sil = max_end_sil |
| | | self.max_end_sil = max_end_sil if max_end_sil is not None else config["vad_post_conf"]["max_end_silence_time"] |
| | | self.encoder_conf = config["encoder_conf"] |
| | | |
| | | def prepare_cache(self, in_cache: list = []): |
| | | if len(in_cache) > 0: |
| | | return in_cache |
| | | |
| | | for i in range(4): |
| | | cache = np.random.rand(1, 128, 19, 1).astype(np.float32) |
| | | fsmn_layers = self.encoder_conf["fsmn_layers"] |
| | | 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) |
| | | 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) |
| | | |
| | |
| | | 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: |