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/6] =?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/6] =?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/6] =?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/6] =?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) From 6b973518dd7fb223adcc9814eab481ed1158206e Mon Sep 17 00:00:00 2001 From: Djraemon <13706876589@163.com> Date: Fri, 1 Nov 2024 16:23:00 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E5=9C=A8paraformer=E3=80=81vad=E4=B8=A4?= =?UTF-8?q?=E4=B8=AA=E6=A8=A1=E5=9E=8B=E4=B8=AD=E5=8A=A0=E5=85=A5=E5=AF=B9?= =?UTF-8?q?=E9=9F=B3=E9=A2=91=E6=96=87=E4=BB=B6=E5=90=8E=E7=BC=80=E7=9A=84?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=EF=BC=8C=E5=B9=B6=E5=B0=86=E9=9D=9Ewav?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E8=BD=AC=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/paraformer_bin.py | 16 ++++++++++++++++ .../funasr_onnx/paraformer_online_bin.py | 17 +++++++++++++++++ .../python/onnxruntime/funasr_onnx/vad_bin.py | 17 +++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/runtime/python/onnxruntime/funasr_onnx/paraformer_bin.py b/runtime/python/onnxruntime/funasr_onnx/paraformer_bin.py index 4f35fcc864..bde7f442e4 100644 --- a/runtime/python/onnxruntime/funasr_onnx/paraformer_bin.py +++ b/runtime/python/onnxruntime/funasr_onnx/paraformer_bin.py @@ -175,7 +175,23 @@ def plot_wave_timestamp(self, wav, text_timestamp, dest): 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 waveform diff --git a/runtime/python/onnxruntime/funasr_onnx/paraformer_online_bin.py b/runtime/python/onnxruntime/funasr_onnx/paraformer_online_bin.py index ddd857d378..3f63ea020f 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 @@ def infer(self, feats: np.ndarray, feats_len: np.ndarray, cache): 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") + 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 diff --git a/runtime/python/onnxruntime/funasr_onnx/vad_bin.py b/runtime/python/onnxruntime/funasr_onnx/vad_bin.py index 92928a8403..3f21004bfc 100644 --- a/runtime/python/onnxruntime/funasr_onnx/vad_bin.py +++ b/runtime/python/onnxruntime/funasr_onnx/vad_bin.py @@ -143,7 +143,24 @@ def __call__(self, audio_in: Union[str, np.ndarray, List[str]], **kwargs) -> Lis return segments 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 waveform From fadb91d4d1efaa69395435cc336340e33a526421 Mon Sep 17 00:00:00 2001 From: Djraemon <13706876589@163.com> Date: Fri, 1 Nov 2024 16:24:25 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9wav=5Fpath=E7=9A=84?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=B1=BB=E5=9E=8B=EF=BC=8C=E4=BD=BFdemo?= =?UTF-8?q?=E8=83=BD=E5=A4=9F=E9=A1=BA=E5=88=A9=E8=BF=90=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- runtime/python/onnxruntime/demo_paraformer_online.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runtime/python/onnxruntime/demo_paraformer_online.py b/runtime/python/onnxruntime/demo_paraformer_online.py index bb72b41a15..cca5357ab8 100644 --- a/runtime/python/onnxruntime/demo_paraformer_online.py +++ b/runtime/python/onnxruntime/demo_paraformer_online.py @@ -3,7 +3,8 @@ from pathlib import Path model_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(