Compare commits

..

3 Commits

Author SHA1 Message Date
FengQingYunDan
b1f608ba72
Merge 50a88a596dea718c83e535136e9cb46b513cef6f into bf81cdb14a38b674b6e9996dabc97340bc9978d2 2026-06-23 01:09:11 +00:00
zhifu gao
bf81cdb14a
feat: upgrade FunASR + add Fun-ASR-Nano & SenseVoice ASR backends (#2782)
- Upgrade funasr from ==1.0.27 to >=1.3.7
- Add Fun-ASR-Nano (31 languages, Chinese dialects, recommended default)
- Add SenseVoice (ultra-fast 170x realtime, 5 languages)
- Keep original Paraformer as '达摩 ASR (中文经典)' for backward compat
- WebUI shows 3 FunASR options + Faster Whisper

Tested: routing logic verified for all backends (zh/en/ja/ko).
Resolves #2777

Co-authored-by: xiaoyunchong.xyc <xiaoyunchong.xyc@alibaba-inc.com>
2026-06-20 15:44:59 +08:00
SapphireLab
b2cff0cd0a
fix: 多音字修改 (#2791)
* fix: 固定唑的读音

* add: 增加md5检测以更新缓存
2026-06-16 21:46:53 +08:00
7 changed files with 68 additions and 15 deletions

View File

@ -1,5 +1,6 @@
# This code is modified from https://github.com/mozillazg/pypinyin-g2pW
import hashlib
import pickle
import os
@ -14,6 +15,16 @@ current_file_path = os.path.dirname(__file__)
CACHE_PATH = os.path.join(current_file_path, "polyphonic.pickle")
PP_DICT_PATH = os.path.join(current_file_path, "polyphonic.rep")
PP_FIX_DICT_PATH = os.path.join(current_file_path, "polyphonic-fix.rep")
MD5_PATH = os.path.join(current_file_path, "polyphonic.md5")
def get_file_md5(file_path):
if not os.path.exists(file_path):
return ""
hasher = hashlib.md5()
with open(file_path, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hasher.update(chunk)
return hasher.hexdigest()
class G2PWPinyin(Pinyin):
@ -115,13 +126,22 @@ def cache_dict(polyphonic_dict, file_path):
def get_dict():
if os.path.exists(CACHE_PATH):
new_md5 = get_file_md5(PP_DICT_PATH) + get_file_md5(PP_FIX_DICT_PATH)
old_md5 = ""
if os.path.exists(MD5_PATH):
with open(MD5_PATH, "r", encoding="utf-8") as f:
old_md5 = f.read().strip()
need_rebuild = (not os.path.exists(CACHE_PATH)) or (new_md5 != old_md5)
if not need_rebuild:
with open(CACHE_PATH, "rb") as pickle_file:
polyphonic_dict = pickle.load(pickle_file)
else:
print("Rebuilding Polyphonic Dictionary: " + f"{old_md5} -> {new_md5}")
polyphonic_dict = read_dict()
cache_dict(polyphonic_dict, CACHE_PATH)
with open(MD5_PATH, "w", encoding="utf-8") as f:
f.write(new_md5)
return polyphonic_dict

View File

@ -45023,4 +45023,5 @@
鼎铛玉石: ['ding3', 'cheng1', 'yu4', 'shi2']
齿豁头童: ['chi3', 'huo1', 'tou2', 'tong2']
牦牛: ['mao2', 'niu2']
牦: ['mao2']
牦: ['mao2']
唑: ['zuo4']

View File

@ -0,0 +1 @@
13b2211c317c75794123ffdf7c2aea021c75b0c606ad61d7c8b05bb00b64fa21

View File

@ -10,7 +10,7 @@ ffmpeg-python
onnxruntime; platform_machine == "aarch64" or platform_machine == "arm64"
onnxruntime-gpu; platform_machine == "x86_64" or platform_machine == "AMD64"
tqdm
funasr==1.0.27
funasr>=1.3.7
cn2an
pypinyin
pyopenjtalk>=0.4.1

View File

@ -5,15 +5,14 @@ def get_models():
"large-v2",
"large-v3",
"large-v3-turbo",
#"distil-large-v2",
#"distil-large-v3",
#"distil-large-v3.5",
]
return model_size_list
asr_dict = {
"达摩 ASR (中文)": {"lang": ["zh", "yue"], "size": ["large"], "path": "funasr_asr.py", "precision": ["float32"]},
"Fun-ASR-Nano (31语种+方言, 推荐)": {"lang": ["zh", "en", "ja", "ko", "yue", "auto"], "size": ["large"], "path": "funasr_asr.py", "precision": ["float32"]},
"SenseVoice (极速, 5语种)": {"lang": ["zh", "en", "ja", "ko", "yue", "auto"], "size": ["large"], "path": "funasr_asr.py", "precision": ["float32"]},
"达摩 ASR (中文经典)": {"lang": ["zh", "yue"], "size": ["large"], "path": "funasr_asr.py", "precision": ["float32"]},
"Faster Whisper (多语种)": {
"lang": ["auto", "en", "ja", "ko"],
"size": get_models(),

View File

@ -11,9 +11,9 @@ from tqdm import tqdm
funasr_models = {} # 存储模型避免重复加载
def only_asr(input_file, language):
def only_asr(input_file, language, backend="fun-asr-nano"):
try:
model = create_model(language)
model = create_model(language, backend=backend)
text = model.generate(input=input_file)[0]["text"]
except Exception:
text = ""
@ -21,7 +21,39 @@ def only_asr(input_file, language):
return text
def create_model(language="zh"):
def create_model(language="zh", **kwargs):
backend = kwargs.get("backend", "fun-asr-nano")
# For non-classic backends, route to multilingual models regardless of language
if backend in ("fun-asr-nano", "sensevoice") and language != "yue":
import torch
device = "cuda" if torch.cuda.is_available() else "cpu"
cache_key = f"{language}_{backend}"
if cache_key in funasr_models:
return funasr_models[cache_key]
if backend == "fun-asr-nano":
model = AutoModel(
model="FunAudioLLM/Fun-ASR-Nano-2512",
trust_remote_code=True,
hub="hf",
vad_model="fsmn-vad",
device=device,
disable_update=True,
)
print(f"FunASR Fun-ASR-Nano 模型加载完成: {language.upper()}")
else:
model = AutoModel(
model="iic/SenseVoiceSmall",
vad_model="fsmn-vad",
device=device,
disable_update=True,
)
print(f"FunASR SenseVoice 模型加载完成: {language.upper()}")
funasr_models[cache_key] = model
return model
if language == "zh":
path_vad = "tools/asr/models/speech_fsmn_vad_zh-cn-16k-common-pytorch"
path_punc = "tools/asr/models/punc_ct-transformer_zh-cn-common-vocab272727-pytorch"
@ -50,7 +82,7 @@ def create_model(language="zh"):
vad_model_revision = punc_model_revision = ""
model_revision = "master"
else:
raise ValueError(f"{language} is not supported")
raise ValueError(f"{language} is not supported. Supported: zh, yue, ja, en, ko, auto")
if language in funasr_models:
return funasr_models[language]
@ -69,14 +101,14 @@ def create_model(language="zh"):
return model
def execute_asr(input_folder, output_folder, model_size, language):
def execute_asr(input_folder, output_folder, model_size, language, backend="fun-asr-nano"):
input_file_names = os.listdir(input_folder)
input_file_names.sort()
output = []
output_file_name = os.path.basename(input_folder)
model = create_model(language)
model = create_model(language, backend=backend)
for file_name in tqdm(input_file_names):
try:
@ -105,7 +137,7 @@ if __name__ == "__main__":
parser.add_argument("-o", "--output_folder", type=str, required=True, help="Output folder to store transcriptions.")
parser.add_argument("-s", "--model_size", type=str, default="large", help="Model Size of FunASR is Large")
parser.add_argument(
"-l", "--language", type=str, default="zh", choices=["zh", "yue", "auto"], help="Language of the audio files."
"-l", "--language", type=str, default="zh", choices=["zh", "yue", "ja", "en", "ko", "auto"], help="Language of the audio files."
)
parser.add_argument(
"-p", "--precision", type=str, default="float16", choices=["float16", "float32"], help="fp16 or fp32"