彭震东
2024-07-15 f2ed4b3856eaed8abe568e6904ffd8dc3a799f5f
funasr/auto/auto_model.py
@@ -20,7 +20,7 @@
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
@@ -111,11 +111,15 @@
    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)
@@ -164,7 +168,8 @@
        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")))
@@ -210,6 +215,7 @@
        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)
@@ -237,6 +243,10 @@
        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):
@@ -305,7 +315,7 @@
            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