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
Fix audio format (#2159)
Djraemona76f15c78527
diff --git a/runtime/python/onnxruntime/funasr_onnx/sensevoice_bin.py b/runtime/python/onnxruntime/funasr_onnx/sensevoice_bin.pyindex 37c98a8d0..b3d8dcf6e 100644--- a/runtime/python/onnxruntime/funasr_onnx/sensevoice_bin.py+++ b/runtime/python/onnxruntime/funasr_onnx/sensevoice_bin.py@@ -196,7 +196,24 @@ class SenseVoiceSmall:return asr_resdef load_data(self, wav_content: Union[str, np.ndarray, List[str]], fs: int = None) -> List:++ def convert_to_wav(input_path, output_path):+ from pydub import AudioSegment+ try:+ audio = AudioSegment.from_mp3(input_path)+ audio.export(output_path, format="wav")+ print("音频文件为mp3格式,已转换为wav格式")++ except Exception as e:+ print(f"转换失败:{e}")+def load_wav(path: str) -> np.ndarray:+ if not path.lower().endswith('.wav'):+ import os+ input_path = path+ path = os.path.splitext(path)[0]+'.wav'+ convert_to_wav(input_path,path) #将mp3格式转换成wav格式+waveform, _ = librosa.load(path, sr=fs)return waveform@@ -215,6 +232,10 @@ class SenseVoiceSmall:feats, feats_len = [], []for waveform in waveform_list:speech, _ = self.frontend.fbank(waveform)++ if speech is None or speech.size == 0:+ print("detected speech size {speech.size}")+ raise ValueError("Empty speech detected, skipping this waveform.")feat, feat_len = self.frontend.lfr_cmvn(speech)feats.append(feat)feats_len.append(feat_len)