From fdf74bb85cfe3dd0ce6cbaf51ec8d5b3ca3d2039 Mon Sep 17 00:00:00 2001
From: 仁迷 <haoneng.lhn@alibaba-inc.com>
Date: 星期四, 09 二月 2023 17:18:43 +0800
Subject: [PATCH] update persian model recipe

---
 funasr/utils/asr_utils.py |   18 +++++++++++-------
 1 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/funasr/utils/asr_utils.py b/funasr/utils/asr_utils.py
index aa5c9db..76b20a5 100644
--- a/funasr/utils/asr_utils.py
+++ b/funasr/utils/asr_utils.py
@@ -18,7 +18,7 @@
 
 global_asr_language = 'zh-cn'
 
-SUPPORT_AUDIO_TYPE_SETS = ['flac', 'mp3', 'm4a', 'ogg', 'opus', 'wav', 'wma']
+SUPPORT_AUDIO_TYPE_SETS = ['flac', 'mp3', 'ogg', 'opus', 'wav', 'pcm']
 
 def get_version():
     return float(pkg_resources.get_distribution('easyasr').version)
@@ -58,7 +58,7 @@
     if r_recog_type is None and audio_in is not None:
         # audio_in is wav, recog_type is wav_file
         if os.path.isfile(audio_in):
-            audio_type = os.path.basename(audio_in).split(".")[1].lower()
+            audio_type = os.path.basename(audio_in).split(".")[-1].lower()
             if audio_type in SUPPORT_AUDIO_TYPE_SETS:
                 r_recog_type = 'wav'
                 r_audio_format = 'wav'
@@ -128,14 +128,19 @@
 def get_sr_from_wav(fname: str):
     fs = None
     if os.path.isfile(fname):
-        audio, fs = torchaudio.load(fname)
+        audio_type = os.path.basename(fname).split(".")[-1].lower()
+        if audio_type in SUPPORT_AUDIO_TYPE_SETS:
+            if audio_type == "pcm":
+                fs = None
+            else:
+                audio, fs = torchaudio.load(fname)
         return fs
     elif os.path.isdir(fname):
         dir_files = os.listdir(fname)
         for file in dir_files:
             file_path = os.path.join(fname, file)
             if os.path.isfile(file_path):
-                audio_type = os.path.basename(file_path).split(".")[1].lower()
+                audio_type = os.path.basename(file_path).split(".")[-1].lower()
                 if audio_type in SUPPORT_AUDIO_TYPE_SETS:
                     fs = get_sr_from_wav(file_path)
             elif os.path.isdir(file_path):
@@ -153,7 +158,7 @@
         file_path = os.path.join(dir_path, file)
         if os.path.isfile(file_path):
             if ends == ".wav" or ends == ".WAV":
-                audio_type = os.path.basename(file_path).split(".")[1].lower()
+                audio_type = os.path.basename(file_path).split(".")[-1].lower()
                 if audio_type in SUPPORT_AUDIO_TYPE_SETS:
                     return True
                 else:
@@ -173,7 +178,7 @@
     for file in dir_files:
         file_path = os.path.join(dir_path, file)
         if os.path.isfile(file_path):
-            audio_type = os.path.basename(file_path).split(".")[1].lower()
+            audio_type = os.path.basename(file_path).split(".")[-1].lower()
             if audio_type in SUPPORT_AUDIO_TYPE_SETS:
                 wav_list.append(file_path)
         elif os.path.isdir(file_path):
@@ -347,4 +352,3 @@
         percent = 1
     res = int(50 * percent) * '#'
     print('\r[%-50s] %d%%' % (res, int(100 * percent)), end='')
-

--
Gitblit v1.9.1