Spaces:
Running
Running
File size: 5,489 Bytes
eb8c82c 49fc4a4 c7de0f6 b663da0 f9e5028 b75a2aa f9e5028 8812d27 f9e5028 9caae98 eb8c82c 49fc4a4 8812d27 a4249a1 8812d27 49fc4a4 8812d27 49fc4a4 1ce668d 8812d27 1ce668d 8812d27 49fc4a4 1ce668d 8812d27 49fc4a4 1ce668d 8812d27 eb8c82c 8812d27 f64a87d 1ce668d 8812d27 1ce668d f64a87d 8812d27 349b2ad 8812d27 349b2ad 9caae98 8812d27 9caae98 b75a2aa 8812d27 349b2ad b75a2aa eb8c82c b75a2aa 8812d27 b75a2aa 9e96240 eb8c82c df56c7b eb8c82c f9e5028 8812d27 df56c7b 8812d27 f9e5028 eb8c82c 8812d27 49fc4a4 eb8c82c a4249a1 8812d27 858a295 9caae98 8812d27 f9e5028 77f184e a4249a1 77f184e a4249a1 77f184e a4249a1 77f184e a4249a1 77f184e a4249a1 77f184e a4249a1 77f184e 8812d27 eb8c82c f9e5028 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
import tempfile
import gradio as gr
from TTS.utils.synthesizer import Synthesizer
import requests
from os.path import exists
from formatter import preprocess_text
from datetime import datetime
from enum import Enum
import torch
class StressOption(Enum):
AutomaticStress = "Автоматичні наголоси (за словником)"
AutomaticStressWithModel = "Автоматичні наголоси (за допомогою моделі)"
class VoiceOption(Enum):
FemaleVoice = "Олена (жіночий)"
MaleVoice = "Микита (чоловічий)"
def download(url, file_name):
if not exists(file_name):
print(f"Downloading {file_name}")
r = requests.get(url, allow_redirects=True)
with open(file_name, "wb") as file:
file.write(r.content)
else:
print(f"Found {file_name}. Skipping download...")
print("downloading uk/mykyta/vits-tts")
release_number = "v2.0.0"
model_link = f"https://github.com/robinhad/ukrainian-tts/releases/download/{release_number}/model-inference.pth"
config_link = f"https://github.com/robinhad/ukrainian-tts/releases/download/{release_number}/config.json"
speakers_link = f"https://github.com/robinhad/ukrainian-tts/releases/download/{release_number}/speakers.pth"
model_path = "model.pth"
config_path = "config.json"
speakers_path = "speakers.pth"
download(model_link, model_path)
download(config_link, config_path)
download(speakers_link, speakers_path)
badge = (
"https://visitor-badge-reloaded.herokuapp.com/badge?page_id=robinhad.ukrainian-tts"
)
synthesizer = Synthesizer(
model_path,
config_path,
speakers_path,
None,
None,
)
if synthesizer is None:
raise NameError("model not found")
def tts(text: str, voice: str, stress: str):
print("============================")
print("Original text:", text)
print("Voice", voice)
print("Stress:", stress)
print("Time:", datetime.utcnow())
autostress_with_model = True if stress == StressOption.AutomaticStressWithModel.value else False
speaker_name = "male1" if voice == VoiceOption.MaleVoice.value else "female3"
text = preprocess_text(text, autostress_with_model)
text_limit = 1200
text = (
text if len(text) < text_limit else text[0:text_limit]
) # mitigate crashes on hf space
print("Converted:", text)
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
with torch.no_grad():
wavs = synthesizer.tts(text, speaker_name=speaker_name)
synthesizer.save_wav(wavs, fp)
return fp.name, text
iface = gr.Interface(
fn=tts,
inputs=[
gr.inputs.Textbox(
label="Input",
default="Введіть, будь ласка, своє р+ечення.",
),
gr.inputs.Radio(
label="Голос",
choices=[option.value for option in VoiceOption],
default=VoiceOption.FemaleVoice.value
),
gr.inputs.Radio(
label="Наголоси",
choices=[option.value for option in StressOption],
),
],
outputs=[
gr.outputs.Audio(label="Output"),
gr.outputs.Textbox(label="Наголошений текст"),
],
title="🐸💬🇺🇦 - Coqui TTS",
theme="huggingface",
description="Україномовний🇺🇦 TTS за допомогою Coqui TTS (щоб вручну поставити наголос, використовуйте + перед голосною)",
article="Якщо вам подобається, підтримайте за посиланням: [SUPPORT LINK](https://send.monobank.ua/jar/48iHq4xAXm), "
+ "Github: [https://github.com/robinhad/ukrainian-tts](https://github.com/robinhad/ukrainian-tts) \n"
+ "Model training - [Yurii Paniv @robinhad](https://github.com/robinhad) \n"
+ "Mykyta and Olena dataset - [Yehor Smoliakov @egorsmkv](https://github.com/egorsmkv) \n"
+ "Autostress (with dictionary) using [ukrainian-word-stress](https://github.com/lang-uk/ukrainian-word-stress) - [Oleksiy Syvokon @asivokon](https://github.com/asivokon) \n"
+ "Autostress (with model) using [ukrainian-accentor](https://github.com/egorsmkv/ukrainian-accentor) - [Bohdan Mykhailenko @NeonBohdan](https://github.com/NeonBohdan) + [Yehor Smoliakov @egorsmkv](https://github.com/egorsmkv) \n"
+ f'<center><img src="{badge}" alt="visitors badge"/></center>',
examples=[
[
"Введіть, будь ласка, своє речення.",
VoiceOption.FemaleVoice.value,
StressOption.AutomaticStress.value,
],
[
"Введіть, будь ласка, своє речення.",
VoiceOption.MaleVoice.value,
StressOption.AutomaticStress.value,
],
[
"Вв+едіть, будь ласка, св+оє реч+ення.",
VoiceOption.MaleVoice.value,
StressOption.AutomaticStress.value,
],
[
"Привіт, як тебе звати?",
VoiceOption.FemaleVoice.value,
StressOption.AutomaticStress.value,
],
[
"Договір підписано 4 квітня 1949 року.",
VoiceOption.FemaleVoice.value,
StressOption.AutomaticStress.value,
],
],
)
iface.launch(enable_queue=True, prevent_thread_lock=True)
|