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 2.0 (#2186)
Djraemon7e9696f15635
diff --git a/runtime/python/onnxruntime/demo_paraformer_online.py b/runtime/python/onnxruntime/demo_paraformer_online.pyindex bb72b41a1..cca5357ab 100644--- a/runtime/python/onnxruntime/demo_paraformer_online.py+++ b/runtime/python/onnxruntime/demo_paraformer_online.py@@ -3,7 +3,8 @@ from funasr_onnx.paraformer_online_bin import Paraformerfrom pathlib import Pathmodel_dir = "damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-online"-wav_path = ["{}/.cache/modelscope/hub/{}/example/asr_example.wav".format(Path.home(), model_dir)]+#wav_path = ["{}/.cache/modelscope/hub/{}/example/asr_example.wav".format(Path.home(), model_dir)]+wav_path = "{}/.cache/modelscope/hub/{}/example/asr_example.wav".format(Path.home(), model_dir)chunk_size = [5, 10, 5]model = Paraformer(diff --git a/runtime/python/onnxruntime/funasr_onnx/paraformer_bin.py b/runtime/python/onnxruntime/funasr_onnx/paraformer_bin.pyindex 4f35fcc86..bde7f442e 100644--- a/runtime/python/onnxruntime/funasr_onnx/paraformer_bin.py+++ b/runtime/python/onnxruntime/funasr_onnx/paraformer_bin.py@@ -175,7 +175,23 @@ class Paraformer:plt.savefig(plotname, bbox_inches="tight")def 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 waveformdiff --git a/runtime/python/onnxruntime/funasr_onnx/paraformer_online_bin.py b/runtime/python/onnxruntime/funasr_onnx/paraformer_online_bin.pyindex ddd857d37..3f63ea020 100644--- a/runtime/python/onnxruntime/funasr_onnx/paraformer_online_bin.py+++ b/runtime/python/onnxruntime/funasr_onnx/paraformer_online_bin.py@@ -208,7 +208,24 @@ class Paraformer: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 waveformdiff --git a/runtime/python/onnxruntime/funasr_onnx/vad_bin.py b/runtime/python/onnxruntime/funasr_onnx/vad_bin.pyindex 92928a840..3f21004bf 100644--- a/runtime/python/onnxruntime/funasr_onnx/vad_bin.py+++ b/runtime/python/onnxruntime/funasr_onnx/vad_bin.py@@ -143,7 +143,24 @@ class Fsmn_vad:return segmentsdef 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