Open-source speech recognition toolkit for training, inference, streaming ASR, VAD, punctuation, speaker diarization pipelines, and OpenAI-compatible/MCP serving.
Python asraudiochineseemotion-recognitionfunasrmcp-servermultilingual-asropenai-compatible-apiparaformerpunctuationpytorchreal-time-asrspeaker-diarizationspeech-recognitionspeech-to-textstreaming-asrtranscriptionvllmvoice-activity-detectionwhisper-alternative
more audio formats support
仁迷cdac560080de
diff --git a/funasr/datasets/iterable_dataset.py b/funasr/datasets/iterable_dataset.pyindex bed295b00..1fc9270c4 100644--- a/funasr/datasets/iterable_dataset.py+++ b/funasr/datasets/iterable_dataset.py@@ -13,6 +13,7 @@ import kaldiioimport numpy as npimport soundfileimport torch+import torchaudiofrom torch.utils.data.dataset import IterableDatasetfrom typeguard import check_argument_typesimport os.path@@ -20,6 +21,8 @@ import os.pathfrom funasr.datasets.dataset import ESPnetDataset+SUPPORT_AUDIO_TYPE_SETS = ['flac', 'mp3', 'm4a', 'ogg', 'opus', 'wav', 'wma']+def load_kaldi(input):retval = kaldiio.load_mat(input)if isinstance(retval, tuple):@@ -60,7 +63,7 @@ def load_bytes(input):DATA_TYPES = {- "sound": lambda x: soundfile.read(x)[0],+ "sound": lambda x: torchaudio.load(x)[0][0].numpy(),"kaldi_ark": load_kaldi,"bytes": load_bytes,"waveform": lambda x: x,@@ -201,6 +204,11 @@ class IterableESPnetDataset(IterableDataset):uid = os.path.basename(self.path_name_type_list[0][0]).split(".")[0]name = self.path_name_type_list[0][1]_type = self.path_name_type_list[0][2]+ if _type == "sound":+ audio_type = os.path.basename(value).split(".")[1].lower()+ if audio_type not in SUPPORT_AUDIO_TYPE_SETS:+ raise NotImplementedError(+ f'Not supported audio type: {audio_type}')func = DATA_TYPES[_type]array = func(value)data[name] = array@@ -286,6 +294,11 @@ class IterableESPnetDataset(IterableDataset):data = {}# 2.a. Load data streaminglyfor value, (path, name, _type) in zip(values, self.path_name_type_list):+ if _type == "sound":+ audio_type = os.path.basename(value).split(".")[1].lower()+ if audio_type not in SUPPORT_AUDIO_TYPE_SETS:+ raise NotImplementedError(+ f'Not supported audio type: {audio_type}')func = DATA_TYPES[_type]# Load entryarray = func(value)@@ -322,3 +335,4 @@ class IterableESPnetDataset(IterableDataset):if count == 0:raise RuntimeError("No iteration")+diff --git a/funasr/utils/asr_utils.py b/funasr/utils/asr_utils.pyindex 0bf903cb0..aa5c9db36 100644--- a/funasr/utils/asr_utils.py+++ b/funasr/utils/asr_utils.py@@ -4,7 +4,7 @@ import osimport structfrom typing import Any, Dict, List, Union-import librosa+import torchaudioimport numpy as npimport pkg_resourcesfrom modelscope.utils.logger import get_logger@@ -18,6 +18,7 @@ end_color = '\033[0m'global_asr_language = 'zh-cn'+SUPPORT_AUDIO_TYPE_SETS = ['flac', 'mp3', 'm4a', 'ogg', 'opus', 'wav', 'wma']def get_version():return float(pkg_resources.get_distribution('easyasr').version)@@ -57,12 +58,16 @@ def type_checking(audio_in: Union[str, bytes],if r_recog_type is None and audio_in is not None:# audio_in is wav, recog_type is wav_fileif os.path.isfile(audio_in):- if audio_in.endswith('.wav') or audio_in.endswith('.WAV'):+ 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'- elif audio_in.endswith('.scp') or audio_in.endswith('.SCP'):+ elif audio_type == "scp":r_recog_type = 'wav'r_audio_format = 'scp'+ else:+ raise NotImplementedError(+ f'Not supported audio type: {audio_type}')# recog_type is datasets_fileelif os.path.isdir(audio_in):@@ -123,14 +128,15 @@ def get_sr_from_bytes(wav: bytes):def get_sr_from_wav(fname: str):fs = Noneif os.path.isfile(fname):- audio, fs = librosa.load(fname, sr=None)+ audio, fs = torchaudio.load(fname)return fselif 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):- if file_path.endswith('.wav') or file_path.endswith('.WAV'):+ 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):fs = get_sr_from_wav(file_path)@@ -146,7 +152,14 @@ def find_file_by_ends(dir_path: str, ends: str):for file in dir_files:file_path = os.path.join(dir_path, file)if os.path.isfile(file_path):- if file_path.endswith(ends):+ if ends == ".wav" or ends == ".WAV":+ audio_type = os.path.basename(file_path).split(".")[1].lower()+ if audio_type in SUPPORT_AUDIO_TYPE_SETS:+ return True+ else:+ raise NotImplementedError(+ f'Not supported audio type: {audio_type}')+ elif file_path.endswith(ends):return Trueelif os.path.isdir(file_path):if find_file_by_ends(file_path, ends):@@ -160,7 +173,8 @@ def recursion_dir_all_wav(wav_list, dir_path: str) -> List[str]:for file in dir_files:file_path = os.path.join(dir_path, file)if os.path.isfile(file_path):- if file_path.endswith('.wav') or file_path.endswith('.WAV'):+ 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):recursion_dir_all_wav(wav_list, file_path)@@ -333,3 +347,4 @@ def print_progress(percent):percent = 1res = int(50 * percent) * '#'print('\r[%-50s] %d%%' % (res, int(100 * percent)), end='')+