mbarnig commited on
Commit
b59e10d
·
1 Parent(s): 87f0a2b

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +94 -0
app.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/lb-de-fr-en-pt-coqui-vits-tts"
7
+
8
+ my_title = "🇩🇪 🇫🇷 🇬🇧 🇵🇹 Mir schwätzen och Lëtzebuergesch ! 🇱🇺"
9
+ my_description = "First multilingual-multispeaker Text-to-Speech (TTS) synthesizer speaking Luxembourgish. This model is based on [YourTTS](https://github.com/Edresson/YourTTS), thanks to 🐸 [Coqui.ai](https://coqui.ai/)."
10
+ lb_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."
11
+ de_text = "Einst stritten sich Nordwind und Sonne, wer von ihnen beiden wohl der Stärkere wäre, als ein Wanderer, der in einen warmen Mantel gehüllt war, des Weges daherkam."
12
+ fr_text = "La bise et le soleil se disputaient, chacun assurant qu'il était le plus fort, quand ils ont vu un voyageur qui s'avançait, enveloppé dans son manteau."
13
+ en_text = "The North Wind and the Sun were disputing which was the stronger, when a traveler came along wrapped in a warm cloak."
14
+ pt_text = "O vento norte e o Sol discutiam quem era o mais forte, quando surgiu um viajante envolvido numa capa."
15
+
16
+ TTS_VOICES = [
17
+ "Judith",
18
+ "Luc",
19
+ "Kerstin",
20
+ "Ed",
21
+ "Linda"
22
+ ]
23
+
24
+ TTS_LANGUAGES = [
25
+ "x-lb",
26
+ "x-de",
27
+ "fr-fr",
28
+ "en",
29
+ "pt-br"
30
+ ]
31
+
32
+
33
+ my_examples = [
34
+ [lb_text,"x-lb","Luc"],
35
+ [de_text,"x-de","Judith"],
36
+ [fr_text,"fr-fr","Kerstin"],
37
+ [en_text,"en","Ed"],
38
+ [pt_text,"pt-br","Linda"],
39
+ ]
40
+
41
+ my_article = "<h3>User guide</h3><p>1. Press the Submit button to generate a speech file with the default values. 2. Change the default values by clicking an example row. 3. Select a language and a voice and enter your own text. Have fun!</p><p>Go to <a href='https://www.web3.lu/category/audio-technologies/'>Internet with a Brain</a> to read some technical infos.</p>"
42
+
43
+ my_inputs = [
44
+ gr.inputs.Textbox(lines=5, label="Input Text", default=lb_text),
45
+ gr.inputs.Radio(label="Select a language", choices = TTS_LANGUAGES, default = "Lëtzebuergesch"),
46
+ gr.inputs.Radio(label="Select a voice", choices = TTS_VOICES, default = "Judith"),
47
+ ]
48
+
49
+ my_outputs = gr.outputs.Audio(type="file", label="Output Audio")
50
+
51
+ def tts(text: str, speaker_idx: str, language_idx: str):
52
+ best_model_path = hf_hub_download(repo_id=REPO_ID, filename="best_model.pth")
53
+ print(best_model_path)
54
+ config_path = hf_hub_download(repo_id=REPO_ID, filename="config.json")
55
+ print(config_path)
56
+ speakers_path = hf_hub_download(repo_id=REPO_ID, filename="speakers.pth")
57
+ print(speakers_path)
58
+ languages_path = hf_hub_download(repo_id=REPO_ID, filename="language_ids.json")
59
+ print(languages_path)
60
+ speaker_encoder_model_path = hf_hub_download(repo_id=REPO_ID, filename="model_se.pth")
61
+ print(speaker_encoder_model_path)
62
+ speaker_encoder_config_path = hf_hub_download(repo_id=REPO_ID, filename="config_se.json")
63
+ print(speaker_encoder_config_path)
64
+
65
+ # init synthesizer
66
+ synthesizer = Synthesizer(
67
+ best_model_path,
68
+ config_path,
69
+ speakers_path,
70
+ languages_path,
71
+ None,
72
+ None,
73
+ speaker_encoder_model_path,
74
+ speaker_encoder_config_path,
75
+ False
76
+ )
77
+
78
+ # create audio file
79
+ wavs = synthesizer.tts(text, speaker_idx, language_idx)
80
+ with tempfile.NamedTemporaryFile(suffix = ".wav", delete = False) as fp:
81
+ synthesizer.save_wav(wavs, fp)
82
+ return fp.name
83
+
84
+ iface = gr.Interface(
85
+ fn=tts,
86
+ inputs=my_inputs,
87
+ outputs=my_outputs,
88
+ title=my_title,
89
+ description = my_description,
90
+ article = my_article,
91
+ examples = my_examples,
92
+ allow_flagging=False
93
+ )
94
+ iface.launch()