Spaces:
Running
Running
import gradio as gr | |
import tempfile | |
from TTS.utils.synthesizer import Synthesizer | |
from huggingface_hub import hf_hub_download | |
REPO_ID = "denZLS/luxembourgish-female-vits-tts" | |
my_title = "🇱🇺 Lëtzebuergesch Sproochsynthees mat enger Fraestëmm ! 🇱🇺" | |
my_description = "Female Text-to-Speech (TTS) synthesizer speaking Luxembourgish. This model is based on VITS, thanks to 🐸 [Coqui.ai](https://coqui.ai/)." | |
schwäin_text = "Patrull Wëllschwäin : duerch déck an dënn." | |
fuuss_text = "Patrull Fuuss : rau a schlau." | |
wisel_text = "Patrull Wisel : ëmmer flénk." | |
nordwand_text = "An der Zäit hunn sech den Nordwand an d'Sonn gestridden, wie vun hinnen zwee wuel méi staark wier, wéi e Wanderer, deen an ee waarme Mantel agepak war, iwwert de Wee koum. Si goufen sech eens, datt deejéinege fir dee Stäerkste gëlle sollt, deen de Wanderer forcéiere géif, säi Mantel auszedoen. Dunn huet d'Sonn d'Loft mat hire frëndleche Strale gewiermt, a schonn no kuerzer Zäit huet de Wanderer säi Mantel ausgedoen. Do huet den Nordwand missen zouginn, datt d'Sonn vun hinnen zwee dee Stäerkste wier." | |
my_examples = [ | |
[schwäin_text], | |
[fuuss_text], | |
[wisel_text], | |
[nordwand_text] | |
] | |
my_article = "<h3>More Infos</h3>" \ | |
"<table><tr>" \ | |
"<td><image src = 'https://www.web3.lu/wp-content/uploads/2024/07/qubit-bookcovers-200.png' alt = 'bookcovers'></td>" \ | |
"<td><p>User guide : 1. Click an example text below the input field and click the play button in the audio field at the right side of the screen.</p>" \ | |
"<p>2. Enter your own text in the input field, click the submit button, wait for the audio generation and click the play button in the audio field at the right side of the screen.</p>" \ | |
"<p>Technical informations about the development, the training, the model and the dataset are available on my <a href = 'https://github.com/mbarnig/TTS-for-LOD'>Github repository.</a></p>" \ | |
"<p> If you are interested in knowing the whole history of technology projects in relation to the Luxembourgish language, the first volume of my book Qubit Lëtzebuerg is made for you." \ | |
" In chapters 2.1.3. to 2.1.8. you will discover EPISTOLE-PC, CORTINA, SpellChecker, LOD, SYSTRAN, EUROTRA, CRETA, eTranslation, Google Translate, Yandex Translate, Euroscript," \ | |
" Wordbee, LuNa, Strips, Spellux, Spacy, CyanogenMod, Gruut, eSpeak-NG-lb, MaryLux , lb_de_fr_en_pt_COQUI_VITS_TTS, Wav2Vec-XLS-R, Coqui STT, schreimaschinn.lu, Whisper, etc." \ | |
" You will find all the details about this book on my website <a href = 'https://www.web3.lu'>web3.lu : Internet with a Brain.</a></p></td>" \ | |
"</tr></table>" | |
my_inputs = [ | |
gr.Textbox(lines=5, label="Input Text"), | |
] | |
my_outputs = gr.Audio(type="filepath", label="Output Audio") | |
def tts(text: str): | |
best_model_path = hf_hub_download(repo_id=REPO_ID, filename="checkpoint_40000.pth") | |
config_path = hf_hub_download(repo_id=REPO_ID, filename="config.json") | |
# init synthesizer | |
synthesizer = Synthesizer( | |
best_model_path, | |
config_path | |
) | |
# create audio file | |
wavs = synthesizer.tts(text.lower()) | |
with tempfile.NamedTemporaryFile(suffix = ".wav", delete = False) as fp: | |
synthesizer.save_wav(wavs, fp) | |
return fp.name | |
iface = gr.Interface( | |
fn=tts, | |
inputs=my_inputs, | |
outputs=my_outputs, | |
title=my_title, | |
description = my_description, | |
article = my_article, | |
examples = my_examples, | |
allow_flagging=False | |
) | |
iface.launch() |