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
support in_cache
凌匀7109589f0e99
diff --git a/funasr/bin/vad_infer.py b/funasr/bin/vad_infer.pyindex 245757c8d..e1698d03d 100644--- a/funasr/bin/vad_infer.py+++ b/funasr/bin/vad_infer.py@@ -175,7 +175,8 @@ class Speech2VadSegmentOnline(Speech2VadSegment):batch_size = speech.shape[0]segments = [[]] * batch_sizeif self.frontend is not None:- feats, feats_len = self.frontend.forward(speech, speech_lengths, is_final)+ reset = in_cache == dict()+ feats, feats_len = self.frontend.forward(speech, speech_lengths, is_final, reset)fbanks, _ = self.frontend.get_fbank()else:raise Exception("Need to extract feats first, please configure frontend configuration")diff --git a/funasr/models/e2e_vad.py b/funasr/models/e2e_vad.pyindex 594c27ebb..71ed2cffb 100644--- a/funasr/models/e2e_vad.py+++ b/funasr/models/e2e_vad.py@@ -226,7 +226,6 @@ class E2EVadModel(nn.Module):self.vad_opts.frame_in_ms)self.encoder = encoder# init variables- self.is_final = Falseself.data_buf_start_frame = 0self.frm_cnt = 0self.latest_confirmed_speech_frame = 0@@ -257,7 +256,6 @@ class E2EVadModel(nn.Module):self.frontend = frontenddef AllResetDetection(self):- self.is_final = Falseself.data_buf_start_frame = 0self.frm_cnt = 0self.latest_confirmed_speech_frame = 0@@ -473,6 +471,8 @@ class E2EVadModel(nn.Module):def forward(self, feats: torch.Tensor, waveform: torch.tensor, in_cache: Dict[str, torch.Tensor] = dict(),is_final: bool = False) -> Tuple[List[List[List[int]]], Dict[str, torch.Tensor]]:+ if not in_cache:+ self.AllResetDetection()self.waveform = waveform # compute decibel for each frameself.ComputeDecibel()self.ComputeScores(feats, in_cache)diff --git a/funasr/models/frontend/wav_frontend.py b/funasr/models/frontend/wav_frontend.pyindex 35fab57eb..568bbab16 100644--- a/funasr/models/frontend/wav_frontend.py+++ b/funasr/models/frontend/wav_frontend.py@@ -395,8 +395,10 @@ class WavFrontendOnline(AbsFrontend):return feats_pad, feats_lens, lfr_splice_frame_idxsdef forward(- self, input: torch.Tensor, input_lengths: torch.Tensor, is_final: bool = False+ self, input: torch.Tensor, input_lengths: torch.Tensor, is_final: bool = False, reset: bool = True) -> Tuple[torch.Tensor, torch.Tensor]:+ if reset:+ self.cache_reset()batch_size = input.shape[0]assert batch_size == 1, 'we support to extract feature online only when the batch size is equal to 1 now'waveforms, feats, feats_lengths = self.forward_fbank(input, input_lengths) # input shape: B T D@@ -500,4 +502,4 @@ class WavFrontendMel23(AbsFrontend):feats_pad = pad_sequence(feats,batch_first=True,padding_value=0.0)- return feats_pad, feats_lens\ No newline at end of file+ return feats_pad, feats_lens