From 7e9696f15635a83ff810cc86b79c0932cb4c8a27 Mon Sep 17 00:00:00 2001
From: Djraemon <154407769+Djraemon@users.noreply.github.com>
Date: 星期一, 04 十一月 2024 11:04:52 +0800
Subject: [PATCH] Fix audio format 2.0 (#2186)

---
 runtime/python/onnxruntime/funasr_onnx/paraformer_bin.py |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/runtime/python/onnxruntime/funasr_onnx/paraformer_bin.py b/runtime/python/onnxruntime/funasr_onnx/paraformer_bin.py
index 4f35fcc..bde7f44 100644
--- a/runtime/python/onnxruntime/funasr_onnx/paraformer_bin.py
+++ b/runtime/python/onnxruntime/funasr_onnx/paraformer_bin.py
@@ -175,7 +175,23 @@
         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("闊抽鏂囦欢涓簃p3鏍煎紡锛屽凡杞崲涓簑av鏍煎紡")
+                
+            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) #灏唌p3鏍煎紡杞崲鎴恮av鏍煎紡
+
             waveform, _ = librosa.load(path, sr=fs)
             return waveform
 

--
Gitblit v1.9.1