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
修复 当选用SenseVoice模型处理长音频(同时开启vad和output_timestamp)时的异常 (#2413)
hohaiuhsx6fe10a8dbfba
diff --git a/funasr/models/sense_voice/model.py b/funasr/models/sense_voice/model.pyindex 70cd02e38..945a30181 100644--- a/funasr/models/sense_voice/model.py+++ b/funasr/models/sense_voice/model.py@@ -925,11 +925,11 @@ class SenseVoiceSmall(nn.Module):align = ctc_forced_align(logits_speech.unsqueeze(0).float(),torch.Tensor(token_int[4:]).unsqueeze(0).long().to(logits_speech.device),- (encoder_out_lens - 4).long(),+ (encoder_out_lens[i] - 4).long(),torch.tensor(len(token_int) - 4).unsqueeze(0).long().to(logits_speech.device),ignore_id=self.ignore_id,)- pred = groupby(align[0, : encoder_out_lens[0]])+ pred = groupby(align[0, : encoder_out_lens[i]])_start = 0token_id = 0ts_max = encoder_out_lens[i] - 4@@ -951,20 +951,26 @@ class SenseVoiceSmall(nn.Module):def post(self, timestamp):timestamp_new = []+ prev_word = Nonefor i, t in enumerate(timestamp):word, start, end = t+ start = int(start * 1000)+ end = int(end * 1000)if word == "▁":continueif i == 0:# timestamp_new.append([word, start, end])- timestamp_new.append([int(start * 1000), int(end * 1000)])- elif word.startswith("▁") or len(word) == 1 or not word[1].isalpha():+ timestamp_new.append([start, end])+ elif word.startswith("▁"):word = word[1:]- # timestamp_new.append([word, start, end])- timestamp_new.append([int(start * 1000), int(end * 1000)])+ timestamp_new.append([start, end])+ elif prev_word.isalpha() and prev_word.isascii() and word.isalpha() and word.isascii():+ prev_word += word+ timestamp_new[-1][1] = endelse:# timestamp_new[-1][0] += word- timestamp_new[-1][1] = int(end * 1000)+ timestamp_new.append([start, end])+ prev_word = wordreturn timestamp_newdef export(self, **kwargs):