Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,8 @@
|
|
1 |
import torch
|
2 |
import gradio as gr
|
3 |
-
import torchaudio
|
4 |
from transformers import VitsModel, VitsTokenizer
|
5 |
-
from numToAce import convert_number_to_aceh
|
6 |
|
|
|
7 |
model_id = "facebook/mms-tts-ace"
|
8 |
tokenizer = VitsTokenizer.from_pretrained(model_id)
|
9 |
model = VitsModel.from_pretrained(model_id)
|
@@ -11,23 +10,27 @@ model = VitsModel.from_pretrained(model_id)
|
|
11 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
12 |
model.to(device)
|
13 |
|
|
|
14 |
def tts_aceh(text):
|
15 |
-
text = convert_number_to_aceh(text)
|
16 |
inputs = tokenizer(text, return_tensors="pt").to(device)
|
17 |
-
|
18 |
with torch.no_grad():
|
19 |
-
|
20 |
-
|
21 |
-
waveform = outputs.waveform.squeeze().cpu()
|
22 |
sample_rate = model.config.sampling_rate
|
23 |
return (sample_rate, waveform)
|
24 |
|
|
|
25 |
demo = gr.Interface(
|
26 |
fn=tts_aceh,
|
27 |
-
inputs=gr.Textbox(label="
|
28 |
-
outputs=gr.Audio(label="
|
29 |
-
title="TTS
|
30 |
-
description=
|
|
|
|
|
|
|
|
|
|
|
31 |
)
|
32 |
|
33 |
if __name__ == "__main__":
|
|
|
1 |
import torch
|
2 |
import gradio as gr
|
|
|
3 |
from transformers import VitsModel, VitsTokenizer
|
|
|
4 |
|
5 |
+
# Load the TTS model and tokenizer for Acehnese
|
6 |
model_id = "facebook/mms-tts-ace"
|
7 |
tokenizer = VitsTokenizer.from_pretrained(model_id)
|
8 |
model = VitsModel.from_pretrained(model_id)
|
|
|
10 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
11 |
model.to(device)
|
12 |
|
13 |
+
# TTS function
|
14 |
def tts_aceh(text):
|
|
|
15 |
inputs = tokenizer(text, return_tensors="pt").to(device)
|
|
|
16 |
with torch.no_grad():
|
17 |
+
output = model(**inputs)
|
18 |
+
waveform = output.waveform[0].cpu().numpy()
|
|
|
19 |
sample_rate = model.config.sampling_rate
|
20 |
return (sample_rate, waveform)
|
21 |
|
22 |
+
# Gradio UI
|
23 |
demo = gr.Interface(
|
24 |
fn=tts_aceh,
|
25 |
+
inputs=gr.Textbox(label="Enter Acehnese text"),
|
26 |
+
outputs=gr.Audio(type="numpy", label="Generated Speech"),
|
27 |
+
title="Acehnese TTS (Text-to-Speech)",
|
28 |
+
description=(
|
29 |
+
"This is a text-to-speech tool for the Acehnese language using Meta's MMS model. "
|
30 |
+
"To use: 1) Enter text in Acehnese, 2) Click Submit to hear it spoken aloud.\n\n"
|
31 |
+
"Note: Reuse, redistribution, or derivative use is not allowed unless you ask for permission. "
|
32 |
+
"Enjoy responsibly, and feel free to share feedback or support!"
|
33 |
+
)
|
34 |
)
|
35 |
|
36 |
if __name__ == "__main__":
|