MCPcopy Create free account
hub / github.com/modelscope/FunASR / inference

Method inference

funasr/models/scama/model.py:741–849  ·  view source on GitHub ↗

Run inference on input data. Args: data_in: Input data (audio samples, file paths, or text). data_lengths: Lengths of each input sample in the batch. key: Sample identifiers. tokenizer: Tokenizer instance for text e

(
        self,
        data_in,
        data_lengths=None,
        key: list = None,
        tokenizer=None,
        frontend=None,
        cache: dict = None,
        **kwargs,
    )

Source from the content-addressed store, hash-verified

739 return cache
740
741 def inference(
742 self,
743 data_in,
744 data_lengths=None,
745 key: list = None,
746 tokenizer=None,
747 frontend=None,
748 cache: dict = None,
749 **kwargs,
750 ):
751 """Run inference on input data.
752
753 Args:
754 data_in: Input data (audio samples, file paths, or text).
755 data_lengths: Lengths of each input sample in the batch.
756 key: Sample identifiers.
757 tokenizer: Tokenizer instance for text encoding/decoding.
758 frontend: Audio frontend for feature extraction.
759 cache: State cache dict for streaming inference.
760 **kwargs: Additional keyword arguments.
761 """
762 if cache is None:
763 cache = {}
764
765 # init beamsearch
766 is_use_ctc = kwargs.get("decoding_ctc_weight", 0.0) > 0.00001 and self.ctc != None
767 is_use_lm = (
768 kwargs.get("lm_weight", 0.0) > 0.00001 and kwargs.get("lm_file", None) is not None
769 )
770
771 if self.beam_search is None:
772
773 logging.info("enable beam_search")
774 self.init_beam_search(**kwargs)
775 self.nbest = kwargs.get("nbest", 1)
776
777 if len(cache) == 0:
778 self.init_cache(cache, **kwargs)
779
780 meta_data = {}
781 chunk_size = kwargs.get("chunk_size", [0, 10, 5])
782 chunk_stride_samples = int(chunk_size[1] * 960) # 600ms
783
784 time1 = time.perf_counter()
785 cfg = {"is_final": kwargs.get("is_final", False)}
786 audio_sample_list = load_audio_text_image_video(
787 data_in,
788 fs=frontend.fs,
789 audio_fs=kwargs.get("fs", 16000),
790 data_type=kwargs.get("data_type", "sound"),
791 tokenizer=tokenizer,
792 cache=cfg,
793 )
794 _is_final = cfg["is_final"] # if data_in is a file or url, set is_final=True
795
796 time2 = time.perf_counter()
797 meta_data["load_data"] = f"{time2 - time1:0.3f}"
798 assert len(audio_sample_list) == 1, "batch_size must be set 1"

Callers

nothing calls this directly

Calls 6

init_beam_searchMethod · 0.95
init_cacheMethod · 0.95
generate_chunkMethod · 0.95
extract_fbankFunction · 0.90
DatadirWriterClass · 0.90

Tested by

no test coverage detected