More silero languages (#3950)

This commit is contained in:
missionfloyd 2023-10-16 14:12:32 -06:00 committed by GitHub
parent db7ecdd274
commit c0ffb77fd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 189 additions and 27 deletions

View File

@ -0,0 +1,176 @@
{
"English": {
"lang_id": "en",
"voices": ["en_99", "en_45", "en_18", "en_117", "en_49", "en_51", "en_68", "en_0", "en_26", "en_56", "en_74", "en_5", "en_38", "en_53", "en_21", "en_37", "en_107", "en_10", "en_82", "en_16", "en_41", "en_12", "en_67", "en_61", "en_14", "en_11", "en_39", "en_52", "en_24", "en_97", "en_28", "en_72", "en_94", "en_36", "en_4", "en_43", "en_88", "en_25", "en_65", "en_6", "en_44", "en_75", "en_91", "en_60", "en_109", "en_85", "en_101", "en_108", "en_50", "en_96", "en_64", "en_92", "en_76", "en_33", "en_116", "en_48", "en_98", "en_86", "en_62", "en_54", "en_95", "en_55", "en_111", "en_3", "en_83", "en_8", "en_47", "en_59", "en_1", "en_2", "en_7", "en_9", "en_13", "en_15", "en_17", "en_19", "en_20", "en_22", "en_23", "en_27", "en_29", "en_30", "en_31", "en_32", "en_34", "en_35", "en_40", "en_42", "en_46", "en_57", "en_58", "en_63", "en_66", "en_69", "en_70", "en_71", "en_73", "en_77", "en_78", "en_79", "en_80", "en_81", "en_84", "en_87", "en_89", "en_90", "en_93", "en_100", "en_102", "en_103", "en_104", "en_105", "en_106", "en_110", "en_112", "en_113", "en_114", "en_115"],
"default_voice": "en_56",
"model_id": "v3_en"
},
"Spanish": {
"lang_id": "es",
"voices": ["es_0", "es_1", "es_2"],
"default_voice": "es_0",
"model_id": "v3_es"
},
"French": {
"lang_id": "fr",
"voices": ["fr_0", "fr_1", "fr_2", "fr_3", "fr_4", "fr_5"],
"default_voice": "fr_0",
"model_id": "v3_fr"
},
"German": {
"lang_id": "de",
"voices": ["bernd_ungerer", "eva_k", "friedrich", "hokuspokus", "karlsson"],
"default_voice": "eva_k",
"model_id": "v3_de"
},
"Russian": {
"lang_id": "ru",
"voices": ["aidar", "baya", "kseniya", "xenia"],
"default_voice": "aidar",
"model_id": "ru_v3"
},
"Tatar": {
"lang_id": "tt",
"voices": ["dilyara"],
"default_voice": "dilyara",
"model_id": "v3_tt"
},
"Ukranian": {
"lang_id": "ua",
"voices": ["mykyta"],
"default_voice": "mykyta",
"model_id": "v3_ua"
},
"Uzbek": {
"lang_id": "uz",
"voices": ["dilnavoz"],
"default_voice": "dilnavoz",
"model_id": "v3_uz"
},
"English (India)": {
"lang_id": "en",
"voices": ["tamil_female", "bengali_female", "malayalam_male", "manipuri_female", "assamese_female", "gujarati_male", "telugu_male", "kannada_male", "hindi_female", "rajasthani_female", "kannada_female", "bengali_male", "tamil_male", "gujarati_female", "assamese_male"],
"default_voice": "hindi_female",
"model_id": "v3_en_indic"
},
"Avar": {
"lang_id": "cyrillic",
"voices": ["b_ava"],
"default_voice": "b_ava",
"model_id": "v4_cyrillic"
},
"Bashkir": {
"lang_id": "cyrillic",
"voices": ["b_bashkir"],
"default_voice": "b_bashkir",
"model_id": "v4_cyrillic"
},
"Bulgarian": {
"lang_id": "cyrillic",
"voices": ["b_bulb", "b_bulc"],
"default_voice": "b_bulb",
"model_id": "v4_cyrillic"
},
"Chechen": {
"lang_id": "cyrillic",
"voices": ["cv_ekaterina", "b_cv"],
"default_voice": "b_che",
"model_id": "v4_cyrillic"
},
"Chuvash": {
"lang_id": "cyrillic",
"voices": ["b_che"],
"default_voice": "b_che",
"model_id": "v4_cyrillic"
},
"Erzya": {
"lang_id": "cyrillic",
"voices": ["b_myv"],
"default_voice": "b_myv",
"model_id": "v4_cyrillic"
},
"Kalmyk": {
"lang_id": "cyrillic",
"voices": ["b_kalmyk"],
"default_voice": "b_kalmyk",
"model_id": "v4_cyrillic"
},
"Karachay-Balkar": {
"lang_id": "cyrillic",
"voices": ["b_krc"],
"default_voice": "b_krc",
"model_id": "v4_cyrillic"
},
"Kazakh": {
"lang_id": "cyrillic",
"voices": ["kz_F1", "kz_F2", "kz_F3", "kz_M1", "kz_M1"],
"default_voice": "kz_F1",
"model_id": "v4_cyrillic"
},
"Khakas": {
"lang_id": "cyrillic",
"voices": ["b_kjh"],
"default_voice": "b_kjh",
"model_id": "v4_cyrillic"
},
"Komi-Ziryan": {
"lang_id": "cyrillic",
"voices": ["b_kpv"],
"default_voice": "b_kpv",
"model_id": "v4_cyrillic"
},
"Lezghian": {
"lang_id": "cyrillic",
"voices": ["b_lez"],
"default_voice": "b_lez",
"model_id": "v4_cyrillic"
},
"Mari": {
"lang_id": "cyrillic",
"voices": ["b_mhr"],
"default_voice": "b_mhr",
"model_id": "v4_cyrillic"
},
"Mari High": {
"lang_id": "cyrillic",
"voices": ["b_mrj"],
"default_voice": "b_mrj",
"model_id": "v4_cyrillic"
},
"Nogai": {
"lang_id": "cyrillic",
"voices": ["b_nog"],
"default_voice": "b_nog",
"model_id": "v4_cyrillic"
},
"Ossetic": {
"lang_id": "cyrillic",
"voices": ["b_oss"],
"default_voice": "b_nog",
"model_id": "v4_cyrillic"
},
"Tuvinian": {
"lang_id": "cyrillic",
"voices": ["b_tyv"],
"default_voice": "b_tyv",
"model_id": "v4_cyrillic"
},
"Udmurt": {
"lang_id": "cyrillic",
"voices": ["b_udm"],
"default_voice": "b_udm",
"model_id": "v4_cyrillic"
},
"Yakut": {
"lang_id": "cyrillic",
"voices": ["b_sah"],
"default_voice": "b_sah",
"model_id": "v4_cyrillic"
},
"Kalmyk": {
"lang_id": "cyrillic",
"voices": ["kalmyk_delghir", "kalmyk_erdni"],
"default_voice": "kalmyk_delghir",
"model_id": "v4_cyrillic"
}
}

View File

@ -1,4 +1,5 @@
import html
import json
import random
import time
from pathlib import Path
@ -16,7 +17,7 @@ torch._C._jit_set_profiling_mode(False)
params = {
'activate': True,
'speaker': 'en_56',
'language': 'en',
'language': 'English',
'model_id': 'v3_en',
'sample_rate': 48000,
'device': 'cpu',
@ -29,23 +30,8 @@ params = {
current_params = params.copy()
voices_en = ['en_99', 'en_45', 'en_18', 'en_117', 'en_49', 'en_51', 'en_68', 'en_0', 'en_26', 'en_56', 'en_74', 'en_5', 'en_38', 'en_53', 'en_21', 'en_37', 'en_107', 'en_10', 'en_82', 'en_16', 'en_41', 'en_12', 'en_67', 'en_61', 'en_14', 'en_11', 'en_39', 'en_52', 'en_24', 'en_97', 'en_28', 'en_72', 'en_94', 'en_36', 'en_4', 'en_43', 'en_88', 'en_25', 'en_65', 'en_6', 'en_44', 'en_75', 'en_91', 'en_60', 'en_109', 'en_85', 'en_101', 'en_108', 'en_50', 'en_96', 'en_64', 'en_92', 'en_76', 'en_33', 'en_116', 'en_48', 'en_98', 'en_86', 'en_62', 'en_54', 'en_95', 'en_55', 'en_111', 'en_3', 'en_83', 'en_8', 'en_47', 'en_59', 'en_1', 'en_2', 'en_7', 'en_9', 'en_13', 'en_15', 'en_17', 'en_19', 'en_20', 'en_22', 'en_23', 'en_27', 'en_29', 'en_30', 'en_31', 'en_32', 'en_34', 'en_35', 'en_40', 'en_42', 'en_46', 'en_57', 'en_58', 'en_63', 'en_66', 'en_69', 'en_70', 'en_71', 'en_73', 'en_77', 'en_78', 'en_79', 'en_80', 'en_81', 'en_84', 'en_87', 'en_89', 'en_90', 'en_93', 'en_100', 'en_102', 'en_103', 'en_104', 'en_105', 'en_106', 'en_110', 'en_112', 'en_113', 'en_114', 'en_115']
voices_es = ["es_0", "es_1", "es_2"]
voices_fr = ["fr_0", "fr_1", "fr_2", "fr_3", "fr_4", "fr_5"]
voices_de = ["bernd_ungerer", "eva_k", "friedrich", "hokuspokus", "karlsson"]
voices_ru = ["aidar", "baya", "kseniya", "xenia"]
voices_ua = ["mykyta"]
voices_uz = ["dilnavoz"]
languages = {
"en": {"label": "English", "voices": voices_en, "default_voice": "en_56", "model_id": "v3_en"},
"es": {"label": "Español", "voices": voices_es, "default_voice": "es_0", "model_id": "v3_es"},
"fr": {"label": "Français", "voices": voices_fr, "default_voice": "fr_0", "model_id": "v3_fr"},
"de": {"label": "Deutsch", "voices": voices_de, "default_voice": "eva_k", "model_id": "v3_de"},
"ru": {"label": "русский", "voices": voices_ru, "default_voice": "aidar", "model_id": "ru_v3"},
"ua": {"label": "українська", "voices": voices_ua, "default_voice": "mykyta", "model_id": "v3_ua"},
"uz": {"label": "Oʻzbekcha", "voices": voices_uz, "default_voice": "dilnavoz", "model_id": "v3_uz"},
}
with open(Path("extensions/silero_tts/languages.json"), encoding='utf8') as f:
languages = json.load(f)
voice_pitches = ['x-low', 'low', 'medium', 'high', 'x-high']
voice_speeds = ['x-slow', 'slow', 'medium', 'fast', 'x-fast']
@ -69,10 +55,10 @@ def load_model():
model_path = torch_cache_path + "/snakers4_silero-models_master/src/silero/model/" + params['model_id'] + ".pt"
if Path(model_path).is_file():
print(f'\nUsing Silero TTS cached checkpoint found at {torch_cache_path}')
model, example_text = torch.hub.load(repo_or_dir=torch_cache_path + '/snakers4_silero-models_master/', model='silero_tts', language=params['language'], speaker=params['model_id'], source='local', path=model_path, force_reload=True)
model, example_text = torch.hub.load(repo_or_dir=torch_cache_path + '/snakers4_silero-models_master/', model='silero_tts', language=languages[params['language']]["lang_id"], speaker=params['model_id'], source='local', path=model_path, force_reload=True)
else:
print(f'\nSilero TTS cache not found at {torch_cache_path}. Attempting to download...')
model, example_text = torch.hub.load(repo_or_dir='snakers4/silero-models', model='silero_tts', language=params['language'], speaker=params['model_id'])
model, example_text = torch.hub.load(repo_or_dir='snakers4/silero-models', model='silero_tts', language=languages[params['language']]["lang_id"], speaker=params['model_id'])
model.to(params['device'])
return model
@ -137,6 +123,7 @@ def output_modifier(string, state):
return string
original_string = string
string = tts_preprocessor.preprocess(html.unescape(string))
if string == '':
@ -166,7 +153,7 @@ def random_sentence():
return random.choice(list(f))
def voice_preview(preview_text):
def voice_preview(string):
global model, current_params, streaming_state
for i in params:
@ -175,7 +162,7 @@ def voice_preview(preview_text):
current_params = params.copy()
break
string = tts_preprocessor.preprocess(preview_text or random_sentence())
string = tts_preprocessor.preprocess(string or random_sentence())
output_file = Path('extensions/silero_tts/outputs/voice_preview.wav')
prosody = f"<prosody rate=\"{params['voice_speed']}\" pitch=\"{params['voice_pitch']}\">"
@ -187,9 +174,8 @@ def voice_preview(preview_text):
def language_change(lang):
global params
lang_code = list(languages.keys())[lang]
params.update({"language": lang_code, "speaker": languages[lang_code]["default_voice"], "model_id": languages[lang_code]["model_id"]})
return gr.update(choices=languages[lang_code]["voices"], value=languages[lang_code]["default_voice"])
params.update({"language": lang, "speaker": languages[lang]["default_voice"], "model_id": languages[lang]["model_id"]})
return gr.update(choices=languages[lang]["voices"], value=languages[lang]["default_voice"])
def custom_css():
@ -207,8 +193,8 @@ def ui():
show_text = gr.Checkbox(value=params['show_text'], label='Show message text under audio player')
with gr.Row():
language = gr.Dropdown(value=languages[params['language']]["label"], choices=[v["label"] for _, v in languages.items()], label='Language', type="index")
voice = gr.Dropdown(value=params['speaker'], choices=voices_en, label='TTS voice')
language = gr.Dropdown(value=params['language'], choices=sorted(languages.keys()), label='Language')
voice = gr.Dropdown(value=params['speaker'], choices=languages[params['language']]["voices"], label='TTS voice')
with gr.Row():
v_pitch = gr.Dropdown(value=params['voice_pitch'], choices=voice_pitches, label='Voice pitch')
v_speed = gr.Dropdown(value=params['voice_speed'], choices=voice_speeds, label='Voice speed')