mbarnig commited on
Commit
e027fad
·
verified ·
1 Parent(s): e26665f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -0
app.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tempfile
3
+ from TTS.utils.synthesizer import Synthesizer
4
+ from huggingface_hub import hf_hub_download
5
+
6
+ REPO_ID = "mbarnig/MULTI_LOD_TTS"
7
+
8
+ my_title = "🇩🇪 🇫🇷 🇬🇧 🇵🇹 Mir schwätzen wéi e Lëtzebuerger ! 🇱🇺"
9
+ my_description = "Multilingual-Multispeaker Text-to-Speech (TTS) synthesizer speaking the five current languages in Luxembourg. This model is based on VITS, thanks to 🐸 [Coqui.ai](https://coqui.ai/)."
10
+
11
+ TTS_VOICES = [
12
+ Mann,
13
+ Fra
14
+ ]
15
+
16
+ TTS_LANGUAGES = [
17
+ "Deutsch",
18
+ "English",
19
+ "Français",
20
+ "Lëtzebuergesch",
21
+ "Português"
22
+ ]
23
+
24
+ my_examples = []
25
+
26
+ my_article = "<h3>User guide</h3>"
27
+
28
+ my_inputs = [
29
+ gr.Textbox(lines=5, label="Input Text"),
30
+ gr.Radio(label="Speaker", choices = TTS_VOICES, value = "Judith"),
31
+ gr.Radio(label="Language", choices = TTS_LANGUAGES, value = "Lëtzebuergesch"),
32
+ ]
33
+
34
+ my_outputs = gr.Audio(type="filepath", label="Output Audio")
35
+
36
+ def tts(text: str, speaker_idx: str, language_idx: str):
37
+ best_model_path = hf_hub_download(repo_id=REPO_ID, filename="best_model.pth")
38
+ config_path = hf_hub_download(repo_id=REPO_ID, filename="config.json")
39
+ speakers_path = hf_hub_download(repo_id=REPO_ID, filename="speakers.pth")
40
+ languages_path = hf_hub_download(repo_id=REPO_ID, filename="language_ids.json")
41
+ speaker_encoder_model_path = hf_hub_download(repo_id=REPO_ID, filename="model_se.pth")
42
+ speaker_encoder_config_path = hf_hub_download(repo_id=REPO_ID, filename="config_se.json")
43
+
44
+ # init synthesizer
45
+ synthesizer = Synthesizer(
46
+ best_model_path,
47
+ config_path,
48
+ speakers_path,
49
+ languages_path,
50
+ None,
51
+ None,
52
+ speaker_encoder_model_path,
53
+ speaker_encoder_config_path,
54
+ False
55
+ )
56
+
57
+ # create audio file
58
+ wavs = synthesizer.tts(text, speaker_idx, language_idx)
59
+ with tempfile.NamedTemporaryFile(suffix = ".wav", delete = False) as fp:
60
+ synthesizer.save_wav(wavs, fp)
61
+ return fp.name
62
+
63
+ iface = gr.Interface(
64
+ fn=tts,
65
+ inputs=my_inputs,
66
+ outputs=my_outputs,
67
+ title=my_title,
68
+ description = my_description,
69
+ article = my_article,
70
+ examples = my_examples,
71
+ allow_flagging=False
72
+ )
73
+ iface.launch()