| | |
| | | model_file, device_id, intra_op_num_threads=intra_op_num_threads |
| | | ) |
| | | self.batch_size = batch_size |
| | | self.vad_scorer = E2EVadModel(config["model_conf"]) |
| | | self.vad_scorer_config = config["model_conf"] |
| | | self.max_end_sil = ( |
| | | max_end_sil if max_end_sil is not None else config["model_conf"]["max_end_silence_time"] |
| | | ) |
| | |
| | | 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) |
| | | |
| | | segments = [[]] * self.batch_size |
| | | for beg_idx in range(0, waveform_nums, self.batch_size): |
| | | |
| | | vad_scorer = E2EVadModel(self.vad_scorer_config) |
| | | end_idx = min(waveform_nums, beg_idx + self.batch_size) |
| | | waveform = waveform_list[beg_idx:end_idx] |
| | | feats, feats_len = self.extract_feat(waveform) |
| | |
| | | inputs.extend(in_cache) |
| | | scores, out_caches = self.infer(inputs) |
| | | in_cache = out_caches |
| | | segments_part = self.vad_scorer( |
| | | segments_part = vad_scorer( |
| | | scores, |
| | | waveform_package, |
| | | is_final=is_final, |
| | |
| | | return segments |
| | | |
| | | def load_data(self, wav_content: Union[str, np.ndarray, List[str]], fs: int = None) -> List: |
| | | |
| | | def convert_to_wav(input_path, output_path): |
| | | from pydub import AudioSegment |
| | | try: |
| | | audio = AudioSegment.from_mp3(input_path) |
| | | audio.export(output_path, format="wav") |
| | | print("音频文件为mp3格式,已转换为wav格式") |
| | | |
| | | except Exception as e: |
| | | print(f"转换失败:{e}") |
| | | |
| | | def load_wav(path: str) -> np.ndarray: |
| | | if not path.lower().endswith('.wav'): |
| | | import os |
| | | input_path = path |
| | | path = os.path.splitext(path)[0]+'.wav' |
| | | convert_to_wav(input_path,path) #将mp3格式转换成wav格式 |
| | | |
| | | waveform, _ = librosa.load(path, sr=fs) |
| | | return waveform |
| | | |