Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,44 +7,57 @@ from TTS.utils.synthesizer import Synthesizer
|
|
7 |
# Max input text length
|
8 |
MAX_TXT_LEN = 400
|
9 |
|
10 |
-
#
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
# Download config
|
14 |
config_path = hf_hub_download("sulaimank/luganda_LMs", filename="config.json")
|
15 |
-
model_path = hf_hub_download("sulaimank/luganda_LMs", filename=MODEL_FILE)
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
22 |
|
23 |
-
def tts(text: str):
|
24 |
if len(text) > MAX_TXT_LEN:
|
25 |
text = text[:MAX_TXT_LEN]
|
26 |
print(f"⚠️ Input truncated to {MAX_TXT_LEN} characters.")
|
27 |
|
|
|
28 |
wav = synthesizer.tts(text)
|
29 |
|
30 |
-
# Save temp wav for playback
|
31 |
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
|
32 |
synthesizer.save_wav(wav, fp.name)
|
33 |
return fp.name
|
34 |
|
35 |
# Example sentences
|
36 |
examples = [
|
37 |
-
["
|
|
|
38 |
]
|
39 |
|
40 |
description = """
|
41 |
-
🗣️ **Luganda TTS
|
42 |
-
Convert Luganda text into speech using
|
|
|
43 |
"""
|
44 |
|
45 |
iface = gr.Interface(
|
46 |
fn=tts,
|
47 |
-
inputs=
|
|
|
|
|
|
|
48 |
outputs=gr.Audio(label="Generated Speech", type="filepath"),
|
49 |
examples=examples,
|
50 |
title="Luganda TTS",
|
|
|
7 |
# Max input text length
|
8 |
MAX_TXT_LEN = 400
|
9 |
|
10 |
+
# Map simple names (Model 1, Model 2...) to checkpoint files
|
11 |
+
MODEL_INFO = {
|
12 |
+
"Model 1": "checkpoint_2080000.pth",
|
13 |
+
"Model 2": "checkpoint_2085000.pth",
|
14 |
+
"Model 3": "checkpoint_2090000.pth",
|
15 |
+
"Model 4": "checkpoint_2095000.pth",
|
16 |
+
"Model 5": "checkpoint_2100000.pth",
|
17 |
+
}
|
18 |
|
19 |
+
# Download config once
|
20 |
config_path = hf_hub_download("sulaimank/luganda_LMs", filename="config.json")
|
|
|
21 |
|
22 |
+
def load_synth(model_file):
|
23 |
+
"""Download and initialize the chosen synthesizer"""
|
24 |
+
model_path = hf_hub_download("sulaimank/luganda_LMs", filename=model_file)
|
25 |
+
return Synthesizer(
|
26 |
+
tts_checkpoint=model_path,
|
27 |
+
tts_config_path=config_path
|
28 |
+
)
|
29 |
|
30 |
+
def tts(text: str, model_choice: str):
|
31 |
if len(text) > MAX_TXT_LEN:
|
32 |
text = text[:MAX_TXT_LEN]
|
33 |
print(f"⚠️ Input truncated to {MAX_TXT_LEN} characters.")
|
34 |
|
35 |
+
synthesizer = load_synth(MODEL_INFO[model_choice])
|
36 |
wav = synthesizer.tts(text)
|
37 |
|
38 |
+
# Save temp wav file for playback
|
39 |
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
|
40 |
synthesizer.save_wav(wav, fp.name)
|
41 |
return fp.name
|
42 |
|
43 |
# Example sentences
|
44 |
examples = [
|
45 |
+
["Nnalubaale egabirirwa emigga mingi nnyo, nga mu gino, egisinga obunene mulimu Katonga, nga guno gusibuka mu bitundu eby'obugwanjuba bwa Uganda.", "Model 1"],
|
46 |
+
["Kampala kye kibuga kya Uganda ekikulu.", "Model 5"],
|
47 |
]
|
48 |
|
49 |
description = """
|
50 |
+
🗣️ **Luganda TTS** 🗣️
|
51 |
+
Convert Luganda text into speech using VITS models.
|
52 |
+
Choose one of the available models to compare synthesis quality.
|
53 |
"""
|
54 |
|
55 |
iface = gr.Interface(
|
56 |
fn=tts,
|
57 |
+
inputs=[
|
58 |
+
gr.Textbox(label="Enter Luganda Text", value="Gyebale ko ssebo."),
|
59 |
+
gr.Radio(label="Choose Model", choices=list(MODEL_INFO.keys()), value="Model 1"),
|
60 |
+
],
|
61 |
outputs=gr.Audio(label="Generated Speech", type="filepath"),
|
62 |
examples=examples,
|
63 |
title="Luganda TTS",
|