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
optimize ComputeDecibel in fsmn-vad model by using numpy (#2174)
StevenH1254e8aee1e3
diff --git a/funasr/models/fsmn_vad_streaming/model.py b/funasr/models/fsmn_vad_streaming/model.pyindex 04689bed9..03aaca779 100644--- a/funasr/models/fsmn_vad_streaming/model.py+++ b/funasr/models/fsmn_vad_streaming/model.py@@ -8,6 +8,7 @@ import jsonimport timeimport mathimport torch+import numpy as npfrom torch import nnfrom enum import Enumfrom dataclasses import dataclass@@ -334,18 +335,17 @@ class FsmnVADStreaming(nn.Module):cache["stats"].data_buf_all = torch.cat((cache["stats"].data_buf_all, cache["stats"].waveform[0]))- for offset in range(- 0, cache["stats"].waveform.shape[1] - frame_sample_length + 1, frame_shift_length- ):- cache["stats"].decibel.append(- 10- * math.log10(- (cache["stats"].waveform[0][offset : offset + frame_sample_length])- .square()- .sum()- + 0.000001- )- )++ waveform_numpy = cache["stats"].waveform.numpy()++ offsets = np.arange(0, waveform_numpy.shape[1] - frame_sample_length + 1, frame_shift_length)+ frames = waveform_numpy[0, offsets[:, np.newaxis] + np.arange(frame_sample_length)]++ decibel_numpy = 10 * np.log10(np.sum(np.square(frames), axis=1) + 0.000001)+ decibel_numpy = decibel_numpy.tolist()++ cache["stats"].decibel.extend(decibel_numpy)+def ComputeScores(self, feats: torch.Tensor, cache: dict = {}) -> None:scores = self.encoder(feats, cache=cache["encoder"]).to("cpu") # return B * T * D