Spaces:
Running
Running
File size: 3,298 Bytes
eb8c82c 49fc4a4 c7de0f6 b663da0 f9e5028 b75a2aa f9e5028 eb8c82c 8472231 eb8c82c 49fc4a4 eb8c82c 8472231 f9e5028 8472231 49fc4a4 8472231 cb6b82c 49fc4a4 cb6b82c eb8c82c f64a87d f9e5028 c7de0f6 b75a2aa b231da2 f9e5028 b663da0 b75a2aa eb8c82c b75a2aa eb8c82c ac7672f eb8c82c f9e5028 eb8c82c 49fc4a4 eb8c82c 8472231 3e61708 f9e5028 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 |
import tempfile
import gradio as gr
from TTS.utils.manage import ModelManager
from TTS.utils.synthesizer import Synthesizer
import requests
from os.path import exists
from formatter import preprocess_text
from datetime import datetime
from stress import sentence_to_stress
from enum import Enum
import torch
import gc
class StressOption(Enum):
ManualStress = "Наголоси вручну"
AutomaticStress = "Автоматичні наголоси (Beta)"
MODEL_NAMES = [
"uk/mykyta/vits-tts"
]
MODELS = {}
manager = ModelManager()
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...")
for MODEL_NAME in MODEL_NAMES:
print(f"downloading {MODEL_NAME}")
release_number = "v2.0.0-beta"
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"
model_path = "model.pth"
config_path = "config.json"
download(model_link, model_path)
download(config_link, config_path)
#MODELS[MODEL_NAME] = synthesizer
def tts(text: str, stress: str):
text = preprocess_text(text)
text_limit = 1200
text = text if len(text) < text_limit else text[0:text_limit] # mitigate crashes on hf space
text = sentence_to_stress(text) if stress == StressOption.AutomaticStress.value else text
print(text, datetime.utcnow())
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
with torch.no_grad():
synthesizer = Synthesizer(
model_path, config_path, None, None, None,
)
if synthesizer is None:
raise NameError("model not found")
wavs = synthesizer.tts(text)
synthesizer.save_wav(wavs, fp)
gc.collect()
return fp.name
iface = gr.Interface(
fn=tts,
inputs=[
gr.inputs.Textbox(
label="Input",
default="Введ+іть, б+удь л+аска, сво+є р+ечення.",
),
gr.inputs.Radio(
label="Опції",
choices=[option.value for option in StressOption],
),
],
outputs=gr.outputs.Audio(label="Output"),
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)",
examples=[
["Введ+іть, б+удь л+аска, сво+є р+ечення.", StressOption.ManualStress.value],
["Привіт, як тебе звати?", StressOption.AutomaticStress.value]
]
)
iface.launch(enable_queue=True, prevent_thread_lock=True)
|