Skip to content
3 changes: 2 additions & 1 deletion runtime/python/onnxruntime/demo_paraformer_online.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 16 additions & 0 deletions runtime/python/onnxruntime/funasr_onnx/paraformer_bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 17 additions & 0 deletions runtime/python/onnxruntime/funasr_onnx/paraformer_online_bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 17 additions & 0 deletions runtime/python/onnxruntime/funasr_onnx/vad_bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down