Open-source speech recognition toolkit for training, inference, streaming ASR, VAD, punctuation, speaker diarization pipelines, and OpenAI-compatible/MCP serving.
Python asraudiochineseemotion-recognitionfunasrmcp-servermultilingual-asropenai-compatible-apiparaformerpunctuationpytorchreal-time-asrspeaker-diarizationspeech-recognitionspeech-to-textstreaming-asrtranscriptionvllmvoice-activity-detectionwhisper-alternative
test
语帆a0ffe57b0567
diff --git a/funasr/auto/auto_model.py b/funasr/auto/auto_model.pyindex e95cfd8d1..4cc52a50c 100644--- a/funasr/auto/auto_model.py+++ b/funasr/auto/auto_model.py@@ -24,7 +24,7 @@ try:from funasr.models.campplus.cluster_backend import ClusterBackendexcept:print("If you want to use the speaker diarization, please `pip install hdbscan`")-+import pdbdef prepare_data_iterator(data_in, input_len=None, data_type=None, key=None):"""@@ -210,13 +210,15 @@ class AutoModel:kwargs.update(cfg)model = self.model if model is None else modelmodel.eval()+ pdb.set_trace()batch_size = kwargs.get("batch_size", 1)# if kwargs.get("device", "cpu") == "cpu":# batch_size = 1key_list, data_list = prepare_data_iterator(input, input_len=input_len, data_type=kwargs.get("data_type", None), key=key)-+ pdb.set_trace()+speed_stats = {}asr_result_list = []num_samples = len(data_list)@@ -224,20 +226,25 @@ class AutoModel:pbar = tqdm(colour="blue", total=num_samples, dynamic_ncols=True) if not disable_pbar else Nonetime_speech_total = 0.0time_escape_total = 0.0+ pdb.set_trace()for beg_idx in range(0, num_samples, batch_size):+ pdb.set_trace()end_idx = min(num_samples, beg_idx + batch_size)data_batch = data_list[beg_idx:end_idx]key_batch = key_list[beg_idx:end_idx]batch = {"data_in": data_batch, "key": key_batch}+ pdb.set_trace()if (end_idx - beg_idx) == 1 and kwargs.get("data_type", None) == "fbank": # fbankbatch["data_in"] = data_batch[0]batch["data_lengths"] = input_lentime1 = time.perf_counter()with torch.no_grad():+ pdb.set_trace()results, meta_data = model.inference(**batch, **kwargs)time2 = time.perf_counter()+ pdb.set_trace()asr_result_list.extend(results)# batch_data_time = time_per_frame_s * data_batch_i["speech_lengths"].sum().item()diff --git a/funasr/models/contextual_paraformer/model.py b/funasr/models/contextual_paraformer/model.pyindex 598c074e2..655ca6f58 100644--- a/funasr/models/contextual_paraformer/model.py+++ b/funasr/models/contextual_paraformer/model.py@@ -63,7 +63,6 @@ class ContextualParaformer(Paraformer):crit_attn_smooth = kwargs.get("crit_attn_smooth", 0.0)bias_encoder_dropout_rate = kwargs.get("bias_encoder_dropout_rate", 0.0)- pdb.set_trace()if bias_encoder_type == 'lstm':self.bias_encoder = torch.nn.LSTM(inner_dim, inner_dim, 1, batch_first=True, dropout=bias_encoder_dropout_rate)self.bias_embed = torch.nn.Embedding(self.vocab_size, inner_dim)@@ -81,7 +80,6 @@ class ContextualParaformer(Paraformer):if self.crit_attn_weight > 0:self.attn_loss = torch.nn.L1Loss()self.crit_attn_smooth = crit_attn_smooth- pdb.set_trace()def forward(@@ -313,20 +311,24 @@ class ContextualParaformer(Paraformer):**kwargs,):# init beamsearch+ pdb.set_trace()is_use_ctc = kwargs.get("decoding_ctc_weight", 0.0) > 0.00001 and self.ctc != Noneis_use_lm = kwargs.get("lm_weight", 0.0) > 0.00001 and kwargs.get("lm_file", None) is not Noneif self.beam_search is None and (is_use_lm or is_use_ctc):logging.info("enable beam_search")self.init_beam_search(**kwargs)self.nbest = kwargs.get("nbest", 1)-+ pdb.set_trace()meta_data = {}# extract fbank featstime1 = time.perf_counter()+ pdb.set_trace()audio_sample_list = load_audio_text_image_video(data_in, fs=frontend.fs, audio_fs=kwargs.get("fs", 16000))+ pdb.set_trace()time2 = time.perf_counter()meta_data["load_data"] = f"{time2 - time1:0.3f}"+ pdb.set_trace()speech, speech_lengths = extract_fbank(audio_sample_list, data_type=kwargs.get("data_type", "sound"),frontend=frontend)time3 = time.perf_counter()@@ -334,38 +336,50 @@ class ContextualParaformer(Paraformer):meta_data["batch_data_time"] = speech_lengths.sum().item() * frontend.frame_shift * frontend.lfr_n / 1000+ pdb.set_trace()speech = speech.to(device=kwargs["device"])speech_lengths = speech_lengths.to(device=kwargs["device"])# hotword+ pdb.set_trace()self.hotword_list = self.generate_hotwords_list(kwargs.get("hotword", None), tokenizer=tokenizer, frontend=frontend)+ pdb.set_trace()+# Encoderencoder_out, encoder_out_lens = self.encode(speech, speech_lengths)if isinstance(encoder_out, tuple):encoder_out = encoder_out[0]-+ pdb.set_trace()++# predictorpredictor_outs = self.calc_predictor(encoder_out, encoder_out_lens)pre_acoustic_embeds, pre_token_length, alphas, pre_peak_index = predictor_outs[0], predictor_outs[1], \predictor_outs[2], predictor_outs[3]+ pdb.set_trace()pre_token_length = pre_token_length.round().long()if torch.max(pre_token_length) < 1:return []-+ pdb.set_trace()+decoder_outs = self.cal_decoder_with_predictor(encoder_out, encoder_out_lens,pre_acoustic_embeds,pre_token_length,hw_list=self.hotword_list,clas_scale=kwargs.get("clas_scale", 1.0))+ pdb.set_trace()decoder_out, ys_pad_lens = decoder_outs[0], decoder_outs[1]+ pdb.set_trace()results = []b, n, d = decoder_out.size()+ pdb.set_trace()for i in range(b):x = encoder_out[i, :encoder_out_lens[i], :]am_scores = decoder_out[i, :pre_token_length[i], :]+ pdb.set_trace()if self.beam_search is not None:nbest_hyps = self.beam_search(x=x, am_scores=am_scores, maxlenratio=kwargs.get("maxlenratio", 0.0),