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

Method __call__

funasr/auto/auto_frontend.py:53–122  ·  view source on GitHub ↗

Internal: call . Args: input: Input audio/text data. input_len: TODO. kwargs: Additional keyword arguments. **cfg: Configuration overrides.

(self, input, input_len=None, kwargs=None, **cfg)

Source from the content-addressed store, hash-verified

51 self.kwargs = kwargs
52
53 def __call__(self, input, input_len=None, kwargs=None, **cfg):
54
55 """Internal: call .
56
57 Args:
58 input: Input audio/text data.
59 input_len: TODO.
60 kwargs: Additional keyword arguments.
61 **cfg: Configuration overrides.
62 """
63 kwargs = self.kwargs if kwargs is None else kwargs
64 kwargs.update(cfg)
65
66 key_list, data_list = prepare_data_iterator(input, input_len=input_len)
67 batch_size = kwargs.get("batch_size", 1)
68 device = kwargs.get("device", "cuda")
69 if device == "cpu":
70 batch_size = 1
71
72 meta_data = {}
73
74 result_list = []
75 num_samples = len(data_list)
76 # pbar = tqdm(colour="blue", total=num_samples + 1, dynamic_ncols=True)
77
78 time0 = time.perf_counter()
79 for beg_idx in range(0, num_samples, batch_size):
80 end_idx = min(num_samples, beg_idx + batch_size)
81 data_batch = data_list[beg_idx:end_idx]
82 key_batch = key_list[beg_idx:end_idx]
83
84 # extract fbank feats
85 time1 = time.perf_counter()
86 audio_sample_list = load_audio_text_image_video(
87 data_batch, fs=self.frontend.fs, audio_fs=kwargs.get("fs", 16000)
88 )
89 time2 = time.perf_counter()
90 meta_data["load_data"] = f"{time2 - time1:0.3f}"
91 speech, speech_lengths = extract_fbank(
92 audio_sample_list,
93 data_type=kwargs.get("data_type", "sound"),
94 frontend=self.frontend,
95 **kwargs,
96 )
97 time3 = time.perf_counter()
98 meta_data["extract_feat"] = f"{time3 - time2:0.3f}"
99 meta_data["batch_data_time"] = (
100 speech_lengths.sum().item() * self.frontend.frame_shift * self.frontend.lfr_n / 1000
101 )
102
103 if kwargs.get("return_pt", True):
104 speech, speech_lengths = speech.to(device=device), speech_lengths.to(device=device)
105 else:
106 speech, speech_lengths = speech.numpy(), speech_lengths.numpy()
107 batch = {
108 "input": speech,
109 "input_len": speech_lengths,
110 "key": key_batch,

Callers

nothing calls this directly

Calls 4

prepare_data_iteratorFunction · 0.90
extract_fbankFunction · 0.90
updateMethod · 0.45

Tested by

no test coverage detected