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

Method inference

funasr/models/eres2net/model.py:105–137  ·  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,
        **kwargs,
    )

Source from the content-addressed store, hash-verified

103 return self.model(x)
104
105 def inference(
106 self,
107 data_in,
108 data_lengths=None,
109 key: list = None,
110 tokenizer=None,
111 frontend=None,
112 **kwargs,
113 ):
114 """Run inference on input data.
115
116 Args:
117 data_in: Input data (audio samples, file paths, or text).
118 data_lengths: Lengths of each input sample in the batch.
119 key: Sample identifiers.
120 tokenizer: Tokenizer instance for text encoding/decoding.
121 frontend: Audio frontend for feature extraction.
122 **kwargs: Additional keyword arguments.
123 """
124 meta_data = {}
125 time1 = time.perf_counter()
126 audio_sample_list = load_audio_text_image_video(
127 data_in, fs=16000, audio_fs=kwargs.get("fs", 16000), data_type="sound"
128 )
129 time2 = time.perf_counter()
130 meta_data["load_data"] = f"{time2 - time1:0.3f}"
131 speech, speech_lengths, speech_times = extract_feature(audio_sample_list)
132 speech = speech.to(device=kwargs["device"])
133 time3 = time.perf_counter()
134 meta_data["extract_feat"] = f"{time3 - time2:0.3f}"
135 meta_data["batch_data_time"] = np.array(speech_times).sum().item() / 16000.0
136 results = [{"spk_embedding": self.forward(speech.to(torch.float32))}]
137 return results, meta_data

Callers

nothing calls this directly

Calls 3

forwardMethod · 0.95
extract_featureFunction · 0.90

Tested by

no test coverage detected