| | |
| | | from funasr.download.file import download_from_url |
| | | from funasr.utils.timestamp_tools import timestamp_sentence |
| | | from funasr.utils.timestamp_tools import timestamp_sentence_en |
| | | from funasr.download.download_from_hub import download_model |
| | | from funasr.download.download_model_from_hub import download_model |
| | | from funasr.utils.vad_utils import slice_padding_audio_samples |
| | | from funasr.utils.vad_utils import merge_vad |
| | | from funasr.utils.load_utils import load_audio_text_image_video |
| | |
| | | if isinstance(data_i, str) and os.path.exists(data_i): |
| | | key = misc.extract_filename_without_extension(data_i) |
| | | else: |
| | | key = "rand_key_" + "".join(random.choice(chars) for _ in range(13)) |
| | | if key is None: |
| | | key = "rand_key_" + "".join(random.choice(chars) for _ in range(13)) |
| | | key_list.append(key) |
| | | |
| | | else: # raw text; audio sample point, fbank; bytes |
| | |
| | | |
| | | def __init__(self, **kwargs): |
| | | |
| | | try: |
| | | from funasr.utils.version_checker import check_for_update |
| | | |
| | | check_for_update() |
| | | except: |
| | | pass |
| | | |
| | | log_level = getattr(logging, kwargs.get("log_level", "INFO").upper()) |
| | | logging.basicConfig(level=log_level) |
| | | |
| | | if not kwargs.get("disable_log", True): |
| | | tables.print() |
| | | |
| | | model, kwargs = self.build_model(**kwargs) |
| | | |
| | |
| | | self.spk_kwargs = spk_kwargs |
| | | self.model_path = kwargs.get("model_path") |
| | | |
| | | def build_model(self, **kwargs): |
| | | @staticmethod |
| | | def build_model(**kwargs): |
| | | assert "model" in kwargs |
| | | if "model_conf" not in kwargs: |
| | | logging.info("download models from model hub: {}".format(kwargs.get("hub", "ms"))) |
| | |
| | | kwargs["frontend"] = frontend |
| | | # build model |
| | | model_class = tables.model_classes.get(kwargs["model"]) |
| | | assert model_class is not None, f'{kwargs["model"]} is not registered' |
| | | model_conf = {} |
| | | deep_update(model_conf, kwargs.get("model_conf", {})) |
| | | deep_update(model_conf, kwargs) |
| | | model = model_class(**model_conf, vocab_size=vocab_size) |
| | | model.to(device) |
| | | |
| | | # init_param |
| | | init_param = kwargs.get("init_param", None) |
| | |
| | | model.to(torch.float16) |
| | | elif kwargs.get("bf16", False): |
| | | model.to(torch.bfloat16) |
| | | model.to(device) |
| | | |
| | | if not kwargs.get("disable_log", True): |
| | | tables.print() |
| | | |
| | | return model, kwargs |
| | | |
| | | def __call__(self, *args, **cfg): |
| | |
| | | speed_stats["rtf"] = f"{(time_escape) / batch_data_time:0.3f}" |
| | | description = f"{speed_stats}, " |
| | | if pbar: |
| | | pbar.update(1) |
| | | pbar.update(end_idx - beg_idx) |
| | | pbar.set_description(description) |
| | | time_speech_total += batch_data_time |
| | | time_escape_total += time_escape |
| | |
| | | input, input_len=input_len, model=self.vad_model, kwargs=self.vad_kwargs, **cfg |
| | | ) |
| | | end_vad = time.time() |
| | | |
| | | |
| | | # FIX(gcf): concat the vad clips for sense vocie model for better aed |
| | | if kwargs.get("merge_vad", False): |
| | | for i in range(len(res)): |
| | |
| | | result[k] = restored_data[j][k] |
| | | else: |
| | | result[k] += restored_data[j][k] |
| | | |
| | | |
| | | if not len(result["text"].strip()): |
| | | continue |
| | | return_raw_text = kwargs.get("return_raw_text", False) |
| | |
| | | if return_raw_text: |
| | | result["raw_text"] = raw_text |
| | | result["text"] = punc_res[0]["text"] |
| | | |
| | | |
| | | # speaker embedding cluster after resorted |
| | | if self.spk_model is not None and kwargs.get("return_spk_res", True): |
| | | if raw_text is None: |
| | |
| | | ) |
| | | |
| | | with torch.no_grad(): |
| | | |
| | | if type == "onnx": |
| | | export_dir = export_utils.export_onnx(model=model, data_in=data_list, **kwargs) |
| | | else: |
| | | export_dir = export_utils.export_torchscripts( |
| | | model=model, data_in=data_list, **kwargs |
| | | ) |
| | | export_dir = export_utils.export(model=model, data_in=data_list, **kwargs) |
| | | |
| | | return export_dir |