alp commited on
Commit
2ce1681
1 Parent(s): 3986602
Files changed (2) hide show
  1. app.py +58 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tempfile
3
+ from TTS.utils.synthesizer import Synthesizer
4
+ from huggingface_hub import hf_hub_download
5
+ import torch
6
+
7
+ CUDA = torch.cuda.is_available()
8
+
9
+ REPO_ID = "collectivat/catotron-ona"
10
+
11
+ my_title = "Catotron Text-to-Speech"
12
+ my_description = "This model is based on Fast Speech implemented in 馃惛 [Coqui.ai](https://coqui.ai/)."
13
+
14
+ my_examples = [
15
+ ["Catotron, sintesi de la parla obert i lliure en catal脿"],
16
+ ["Ada Lovelace va ser la primera programadora en la hist貌ria dels ordinadors."],
17
+ ["S'espera un dia anticicl貌nic amb temperatures suaus i vent fluix."]
18
+ ]
19
+
20
+ my_inputs = [
21
+ gr.Textbox(lines=5, label="Input Text")
22
+ ]
23
+
24
+ my_outputs = gr.Audio(type="filepath", label="Output Audio")
25
+
26
+ def tts(text: str, split_sentences: bool = True):
27
+ best_model_path = hf_hub_download(repo_id=REPO_ID, filename="fast-speech_best_model.pth")
28
+ config_path = hf_hub_download(repo_id=REPO_ID, filename="fast-speech_config.json")
29
+
30
+ # init synthesizer
31
+ synthesizer = Synthesizer(
32
+ best_model_path,
33
+ config_path,
34
+ use_cuda=CUDA
35
+ )
36
+
37
+ # replace oov characters
38
+ text = text.replace("\n", ". ")
39
+ text = text.replace("(", ",")
40
+ text = text.replace(")", ",")
41
+ text = text.replace(";", ",")
42
+
43
+ # create audio file
44
+ wavs = synthesizer.tts(text, split_sentences=split_sentences)
45
+ with tempfile.NamedTemporaryFile(suffix = ".wav", delete = False) as fp:
46
+ synthesizer.save_wav(wavs, fp)
47
+ return fp.name
48
+
49
+ iface = gr.Interface(
50
+ fn=tts,
51
+ inputs=my_inputs,
52
+ outputs=my_outputs,
53
+ title=my_title,
54
+ description = my_description,
55
+ examples = my_examples,
56
+ cache_examples=True
57
+ )
58
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ coqui-tts==0.24.3