From d023a91c333b7dbed05f1da693e0362008f7c707 Mon Sep 17 00:00:00 2001 From: dingjingrao <13706876589@163.com> Date: Sun, 20 Oct 2024 00:50:57 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E5=AF=B9?= =?UTF-8?q?=E9=9F=B3=E9=A2=91=E6=96=87=E4=BB=B6=E6=89=A9=E5=B1=95=E5=90=8D?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E4=B8=BA.mp3=E7=9A=84=E8=A1=A5=E4=B8=81?= =?UTF-8?q?=EF=BC=8C=E6=98=AFmp3=E6=A0=BC=E5=BC=8F=E5=88=99=E8=BD=AC?= =?UTF-8?q?=E5=8C=96=E4=B8=BAwav=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../onnxruntime/funasr_onnx/sensevoice_bin.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/runtime/python/onnxruntime/funasr_onnx/sensevoice_bin.py b/runtime/python/onnxruntime/funasr_onnx/sensevoice_bin.py index 37c98a8d06..65fa649c96 100644 --- a/runtime/python/onnxruntime/funasr_onnx/sensevoice_bin.py +++ b/runtime/python/onnxruntime/funasr_onnx/sensevoice_bin.py @@ -196,7 +196,21 @@ def __call__(self, wav_content: Union[str, np.ndarray, List[str]], **kwargs): return asr_res 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") + except Exception as e: + print(f"转换失败:{e}") + def load_wav(path: str) -> np.ndarray: + if path.lower().endswith('.mp3'): + input_path = path + path = input_path.replace('.mp3', '.wav') + convert_to_wav(input_path,path) #将mp3格式转换成wav格式 + waveform, _ = librosa.load(path, sr=fs) return waveform From c50f25ac78c46cef37e985a48de4d101cddba557 Mon Sep 17 00:00:00 2001 From: dingjingrao <13706876589@163.com> Date: Mon, 21 Oct 2024 09:35:01 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E9=9F=B3=E9=A2=91=E6=96=87=E4=BB=B6=E6=98=AF=E5=90=A6=E4=B8=BA?= =?UTF-8?q?mp3=E6=A0=BC=E5=BC=8F=E7=9A=84=E8=A1=A5=E4=B8=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- runtime/python/onnxruntime/funasr_onnx/sensevoice_bin.py | 1 + 1 file changed, 1 insertion(+) diff --git a/runtime/python/onnxruntime/funasr_onnx/sensevoice_bin.py b/runtime/python/onnxruntime/funasr_onnx/sensevoice_bin.py index 65fa649c96..83800a3345 100644 --- a/runtime/python/onnxruntime/funasr_onnx/sensevoice_bin.py +++ b/runtime/python/onnxruntime/funasr_onnx/sensevoice_bin.py @@ -202,6 +202,7 @@ def convert_to_wav(input_path, output_path): try: audio = AudioSegment.from_mp3(input_path) audio.export(output_path, format="wav") + print("音频文件为mp3格式,已转换为wav格式") except Exception as e: print(f"转换失败:{e}") From 3c181c33c09a765f0bd3cc447ab0a33ad37c0db2 Mon Sep 17 00:00:00 2001 From: Djraemon <13706876589@163.com> Date: Mon, 21 Oct 2024 11:26:36 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=AF=B9=E9=9F=B3?= =?UTF-8?q?=E9=A2=91=E6=96=87=E4=BB=B6=E5=90=8E=E7=BC=80=E5=90=8D=E7=9A=84?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=EF=BC=8C=E8=8B=A5=E6=96=87=E4=BB=B6=E5=90=8E?= =?UTF-8?q?=E7=BC=80=E4=B8=8D=E6=98=AF.wav=EF=BC=8C=E5=88=99=E8=BD=AC?= =?UTF-8?q?=E5=8C=96=E4=B8=BAwav?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- runtime/python/onnxruntime/funasr_onnx/sensevoice_bin.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/runtime/python/onnxruntime/funasr_onnx/sensevoice_bin.py b/runtime/python/onnxruntime/funasr_onnx/sensevoice_bin.py index 83800a3345..eddefa3dd7 100644 --- a/runtime/python/onnxruntime/funasr_onnx/sensevoice_bin.py +++ b/runtime/python/onnxruntime/funasr_onnx/sensevoice_bin.py @@ -203,13 +203,15 @@ def convert_to_wav(input_path, output_path): 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 path.lower().endswith('.mp3'): + if not path.lower().endswith('.wav'): + import os input_path = path - path = input_path.replace('.mp3', '.wav') + path = os.path.splitext(path)[0]+'.wav' convert_to_wav(input_path,path) #将mp3格式转换成wav格式 waveform, _ = librosa.load(path, sr=fs) From 5544f78758030ea8cca9495011f7df7ac4e691e4 Mon Sep 17 00:00:00 2001 From: Djraemon <13706876589@163.com> Date: Mon, 21 Oct 2024 12:01:07 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=9F=B3=E9=A2=91?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=90=8E=E7=BC=80=E5=90=8D=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=EF=BC=9B=E9=9F=B3=E9=A2=91=E6=96=87=E4=BB=B6=E6=97=A0=E6=95=88?= =?UTF-8?q?=E6=97=B6=E6=8A=9B=E5=87=BA=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- runtime/python/onnxruntime/funasr_onnx/sensevoice_bin.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/runtime/python/onnxruntime/funasr_onnx/sensevoice_bin.py b/runtime/python/onnxruntime/funasr_onnx/sensevoice_bin.py index eddefa3dd7..b3d8dcf6eb 100644 --- a/runtime/python/onnxruntime/funasr_onnx/sensevoice_bin.py +++ b/runtime/python/onnxruntime/funasr_onnx/sensevoice_bin.py @@ -232,6 +232,10 @@ def extract_feat(self, waveform_list: List[np.ndarray]) -> Tuple[np.ndarray, np. 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)