anzorq commited on
Commit
6eb1048
1 Parent(s): 4e16e51

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from TTS.utils.download import download_url
3
+ from TTS.utils.synthesizer import Synthesizer
4
+ import gradio as gr
5
+ import tempfile
6
+
7
+ # Variables
8
+ MAX_TXT_LEN = 800
9
+ MODEL_DIR = "kbd-vits-tts-male"
10
+ MODEL_URL = "https://huggingface.co/anzorq/kbd-vits-tts-male/resolve/main/checkpoint_56000.pth"
11
+ CONFIG_URL = "https://huggingface.co/anzorq/kbd-vits-tts-male/resolve/main/config_35000.json"
12
+
13
+ # Downloading model and config
14
+ if not os.path.exists(MODEL_DIR):
15
+ os.makedirs(MODEL_DIR)
16
+ download_url(MODEL_URL, MODEL_DIR, "model.pth")
17
+ download_url(CONFIG_URL, MODEL_DIR, "config.json")
18
+
19
+
20
+ def tts(text: str):
21
+ if len(text) > MAX_TXT_LEN:
22
+ text = text[:MAX_TXT_LEN]
23
+ print(f"Input text was cutoff since it went over the {MAX_TXT_LEN} character limit.")
24
+ print(text)
25
+
26
+ # synthesize
27
+ synthesizer = Synthesizer(f"{MODEL_DIR}/model.pth", f"{MODEL_DIR}/config.json")
28
+ wavs = synthesizer.tts(text)
29
+
30
+ # return output
31
+ with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
32
+ synthesizer.save_wav(wavs, fp)
33
+ return fp.name
34
+
35
+ # Gradio interface
36
+ iface = gr.Interface(
37
+ fn=tts,
38
+ inputs=gr.Textbox(
39
+ label="Text",
40
+ value="Default text here if you need it.",
41
+ ),
42
+ outputs=gr.Audio(label="Output", type='filepath'),
43
+ title="KBD TTS",
44
+ live=False
45
+ )
46
+
47
+ iface.launch(share=False)