mirror of
https://github.com/RVC-Boss/GPT-SoVITS.git
synced 2026-07-09 00:01:12 +08:00
Compare commits
1 Commits
b1f608ba72
...
bd3dfa685c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bd3dfa685c |
@ -1,6 +1,5 @@
|
||||
# This code is modified from https://github.com/mozillazg/pypinyin-g2pW
|
||||
|
||||
import hashlib
|
||||
import pickle
|
||||
import os
|
||||
|
||||
@ -15,16 +14,6 @@ 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):
|
||||
@ -126,22 +115,13 @@ def cache_dict(polyphonic_dict, file_path):
|
||||
|
||||
|
||||
def get_dict():
|
||||
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:
|
||||
if os.path.exists(CACHE_PATH):
|
||||
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
|
||||
|
||||
|
||||
|
||||
@ -45023,5 +45023,4 @@
|
||||
鼎铛玉石: ['ding3', 'cheng1', 'yu4', 'shi2']
|
||||
齿豁头童: ['chi3', 'huo1', 'tou2', 'tong2']
|
||||
牦牛: ['mao2', 'niu2']
|
||||
牦: ['mao2']
|
||||
唑: ['zuo4']
|
||||
牦: ['mao2']
|
||||
@ -1 +0,0 @@
|
||||
13b2211c317c75794123ffdf7c2aea021c75b0c606ad61d7c8b05bb00b64fa21
|
||||
Binary file not shown.
@ -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.3.7
|
||||
funasr==1.0.27
|
||||
cn2an
|
||||
pypinyin
|
||||
pyopenjtalk>=0.4.1
|
||||
|
||||
@ -5,14 +5,15 @@ 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 = {
|
||||
"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"]},
|
||||
"达摩 ASR (中文)": {"lang": ["zh", "yue"], "size": ["large"], "path": "funasr_asr.py", "precision": ["float32"]},
|
||||
"Faster Whisper (多语种)": {
|
||||
"lang": ["auto", "en", "ja", "ko"],
|
||||
"size": get_models(),
|
||||
|
||||
@ -11,9 +11,9 @@ from tqdm import tqdm
|
||||
funasr_models = {} # 存储模型避免重复加载
|
||||
|
||||
|
||||
def only_asr(input_file, language, backend="fun-asr-nano"):
|
||||
def only_asr(input_file, language):
|
||||
try:
|
||||
model = create_model(language, backend=backend)
|
||||
model = create_model(language)
|
||||
text = model.generate(input=input_file)[0]["text"]
|
||||
except Exception:
|
||||
text = ""
|
||||
@ -21,39 +21,7 @@ def only_asr(input_file, language, backend="fun-asr-nano"):
|
||||
return text
|
||||
|
||||
|
||||
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
|
||||
|
||||
def create_model(language="zh"):
|
||||
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"
|
||||
@ -82,7 +50,7 @@ def create_model(language="zh", **kwargs):
|
||||
vad_model_revision = punc_model_revision = ""
|
||||
model_revision = "master"
|
||||
else:
|
||||
raise ValueError(f"{language} is not supported. Supported: zh, yue, ja, en, ko, auto")
|
||||
raise ValueError(f"{language} is not supported")
|
||||
|
||||
if language in funasr_models:
|
||||
return funasr_models[language]
|
||||
@ -101,14 +69,14 @@ def create_model(language="zh", **kwargs):
|
||||
return model
|
||||
|
||||
|
||||
def execute_asr(input_folder, output_folder, model_size, language, backend="fun-asr-nano"):
|
||||
def execute_asr(input_folder, output_folder, model_size, language):
|
||||
input_file_names = os.listdir(input_folder)
|
||||
input_file_names.sort()
|
||||
|
||||
output = []
|
||||
output_file_name = os.path.basename(input_folder)
|
||||
|
||||
model = create_model(language, backend=backend)
|
||||
model = create_model(language)
|
||||
|
||||
for file_name in tqdm(input_file_names):
|
||||
try:
|
||||
@ -137,7 +105,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", "ja", "en", "ko", "auto"], help="Language of the audio files."
|
||||
"-l", "--language", type=str, default="zh", choices=["zh", "yue", "auto"], help="Language of the audio files."
|
||||
)
|
||||
parser.add_argument(
|
||||
"-p", "--precision", type=str, default="float16", choices=["float16", "float32"], help="fp16 or fp32"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user