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
bugfix
游雁952c63f69662
diff --git a/funasr/models/bicif_paraformer/model.py b/funasr/models/bicif_paraformer/model.pyindex 0069b8c98..696cd5681 100644--- a/funasr/models/bicif_paraformer/model.py+++ b/funasr/models/bicif_paraformer/model.py@@ -300,9 +300,11 @@ class BiCifParaformer(Paraformer):nbest_hyps = [Hypothesis(yseq=yseq, score=score)]for nbest_idx, hyp in enumerate(nbest_hyps):ibest_writer = None- if ibest_writer is None and kwargs.get("output_dir") is not None:- writer = DatadirWriter(kwargs.get("output_dir"))- ibest_writer = writer[f"{nbest_idx + 1}best_recog"]+ if kwargs.get("output_dir") is not None:+ if not hasattr(self, "writer"):+ self.writer = DatadirWriter(kwargs.get("output_dir"))+ ibest_writer = self.writer[f"{nbest_idx+1}best_recog"]+# remove sos/eos and get resultslast_pos = -1if isinstance(hyp.yseq, list):diff --git a/funasr/models/contextual_paraformer/model.py b/funasr/models/contextual_paraformer/model.pyindex 3f79eedf2..939d46d64 100644--- a/funasr/models/contextual_paraformer/model.py+++ b/funasr/models/contextual_paraformer/model.py@@ -380,9 +380,11 @@ class ContextualParaformer(Paraformer):nbest_hyps = [Hypothesis(yseq=yseq, score=score)]for nbest_idx, hyp in enumerate(nbest_hyps):ibest_writer = None- if ibest_writer is None and kwargs.get("output_dir") is not None:- writer = DatadirWriter(kwargs.get("output_dir"))- ibest_writer = writer[f"{nbest_idx + 1}best_recog"]+ if kwargs.get("output_dir") is not None:+ if not hasattr(self, "writer"):+ self.writer = DatadirWriter(kwargs.get("output_dir"))+ ibest_writer = self.writer[f"{nbest_idx + 1}best_recog"]+# remove sos/eos and get resultslast_pos = -1if isinstance(hyp.yseq, list):diff --git a/funasr/models/fsmn_vad_streaming/model.py b/funasr/models/fsmn_vad_streaming/model.pyindex 4fd18c85f..e29af57d8 100644--- a/funasr/models/fsmn_vad_streaming/model.py+++ b/funasr/models/fsmn_vad_streaming/model.py@@ -625,9 +625,10 @@ class FsmnVADStreaming(nn.Module):self.init_cache(cache)ibest_writer = None- if ibest_writer is None and kwargs.get("output_dir") is not None:- writer = DatadirWriter(kwargs.get("output_dir"))- ibest_writer = writer[f"{1}best_recog"]+ if kwargs.get("output_dir") is not None:+ if not hasattr(self, "writer"):+ self.writer = DatadirWriter(kwargs.get("output_dir"))+ ibest_writer = self.writer[f"{1}best_recog"]results = []result_i = {"key": key[0], "value": segments}diff --git a/funasr/models/monotonic_aligner/model.py b/funasr/models/monotonic_aligner/model.pyindex 77d95a0eb..718923bd6 100644--- a/funasr/models/monotonic_aligner/model.py+++ b/funasr/models/monotonic_aligner/model.py@@ -183,9 +183,11 @@ class MonotonicAligner(torch.nn.Module):results = []ibest_writer = None- if ibest_writer is None and kwargs.get("output_dir") is not None:- writer = DatadirWriter(kwargs.get("output_dir"))- ibest_writer = writer["tp_res"]+ if kwargs.get("output_dir") is not None:+ if not hasattr(self, "writer"):+ self.writer = DatadirWriter(kwargs.get("output_dir"))+ ibest_writer = self.writer["tp_res"]+for i, (us_alpha, us_peak, token_int) in enumerate(zip(us_alphas, us_peaks, text_token_int_list)):token = tokenizer.ids2tokens(token_int)timestamp_str, timestamp = ts_prediction_lfr6_standard(us_alpha[:encoder_out_lens[i] * 3],diff --git a/funasr/models/paraformer/model.py b/funasr/models/paraformer/model.pyindex 77471466b..cf31cdb8b 100644--- a/funasr/models/paraformer/model.py+++ b/funasr/models/paraformer/model.py@@ -514,9 +514,10 @@ class Paraformer(torch.nn.Module):nbest_hyps = [Hypothesis(yseq=yseq, score=score)]for nbest_idx, hyp in enumerate(nbest_hyps):ibest_writer = None- if ibest_writer is None and kwargs.get("output_dir") is not None:- writer = DatadirWriter(kwargs.get("output_dir"))- ibest_writer = writer[f"{nbest_idx+1}best_recog"]+ if kwargs.get("output_dir") is not None:+ if not hasattr(self, "writer"):+ self.writer = DatadirWriter(kwargs.get("output_dir"))+ ibest_writer = self.writer[f"{nbest_idx+1}best_recog"]# remove sos/eos and get resultslast_pos = -1if isinstance(hyp.yseq, list):diff --git a/funasr/models/paraformer_streaming/model.py b/funasr/models/paraformer_streaming/model.pyindex 9bf5d39b2..45875a2da 100644--- a/funasr/models/paraformer_streaming/model.py+++ b/funasr/models/paraformer_streaming/model.py@@ -556,11 +556,12 @@ class ParaformerStreaming(Paraformer):self.init_cache(cache, **kwargs)if kwargs.get("output_dir"):- writer = DatadirWriter(kwargs.get("output_dir"))- ibest_writer = writer[f"{1}best_recog"]+ if not hasattr(self, "writer"):+ self.writer = DatadirWriter(kwargs.get("output_dir"))+ ibest_writer = self.writer[f"{1}best_recog"]ibest_writer["token"][key[0]] = " ".join(tokens)ibest_writer["text"][key[0]] = text_postprocessed-+return result, meta_datadiff --git a/funasr/models/seaco_paraformer/model.py b/funasr/models/seaco_paraformer/model.pyindex 2f55e6e19..06103963b 100644--- a/funasr/models/seaco_paraformer/model.py+++ b/funasr/models/seaco_paraformer/model.py@@ -385,9 +385,11 @@ class SeacoParaformer(BiCifParaformer, Paraformer):nbest_hyps = [Hypothesis(yseq=yseq, score=score)]for nbest_idx, hyp in enumerate(nbest_hyps):ibest_writer = None- if ibest_writer is None and kwargs.get("output_dir") is not None:- writer = DatadirWriter(kwargs.get("output_dir"))- ibest_writer = writer[f"{nbest_idx + 1}best_recog"]+ if kwargs.get("output_dir") is not None:+ if not hasattr(self, "writer"):+ self.writer = DatadirWriter(kwargs.get("output_dir"))+ ibest_writer = self.writer[f"{nbest_idx + 1}best_recog"]+# remove sos/eos and get resultslast_pos = -1if isinstance(hyp.yseq, list):diff --git a/funasr/models/transducer/model.py b/funasr/models/transducer/model.pyindex fd8ad71db..8b876d26d 100644--- a/funasr/models/transducer/model.py+++ b/funasr/models/transducer/model.py@@ -488,9 +488,10 @@ class Transducer(torch.nn.Module):for nbest_idx, hyp in enumerate(nbest_hyps):ibest_writer = None- if ibest_writer is None and kwargs.get("output_dir") is not None:- writer = DatadirWriter(kwargs.get("output_dir"))- ibest_writer = writer[f"{nbest_idx+1}best_recog"]+ if kwargs.get("output_dir") is not None:+ if not hasattr(self, "writer"):+ self.writer = DatadirWriter(kwargs.get("output_dir"))+ ibest_writer = self.writer[f"{nbest_idx + 1}best_recog"]# remove sos/eos and get resultslast_pos = -1if isinstance(hyp.yseq, list):diff --git a/funasr/models/transformer/model.py b/funasr/models/transformer/model.pyindex a92f5af2f..c68ccd7ba 100644--- a/funasr/models/transformer/model.py+++ b/funasr/models/transformer/model.py@@ -423,9 +423,11 @@ class Transformer(nn.Module):for nbest_idx, hyp in enumerate(nbest_hyps):ibest_writer = None- if ibest_writer is None and kwargs.get("output_dir") is not None:- writer = DatadirWriter(kwargs.get("output_dir"))- ibest_writer = writer[f"{nbest_idx+1}best_recog"]+ if kwargs.get("output_dir") is not None:+ if not hasattr(self, "writer"):+ self.writer = DatadirWriter(kwargs.get("output_dir"))+ ibest_writer = self.writer[f"{nbest_idx + 1}best_recog"]+# remove sos/eos and get resultslast_pos = -1if isinstance(hyp.yseq, list):