Spaces:
Running
Running
Update app.py
Browse filesadded new code
app.py
CHANGED
|
@@ -1,2 +1,30 @@
|
|
| 1 |
-
import
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
import soundfile as sf
|
| 4 |
+
import io
|
| 5 |
+
from transformers import SpeechT5ForTextToSpeech, SpeechT5Processor
|
| 6 |
+
|
| 7 |
+
# Load Tibetan MMS-TTS model
|
| 8 |
+
model = SpeechT5ForTextToSpeech.from_pretrained("facebook/mms-tts-bod")
|
| 9 |
+
processor = SpeechT5Processor.from_pretrained("facebook/mms-tts-bod")
|
| 10 |
+
|
| 11 |
+
def tts_tibetan(text):
|
| 12 |
+
inputs = processor(text=text, return_tensors="pt")
|
| 13 |
+
with torch.no_grad():
|
| 14 |
+
speech = model.generate(**inputs)
|
| 15 |
+
|
| 16 |
+
buf = io.BytesIO()
|
| 17 |
+
sf.write(buf, speech.cpu().numpy(), samplerate=16000, format="WAV")
|
| 18 |
+
buf.seek(0)
|
| 19 |
+
return buf.read()
|
| 20 |
+
|
| 21 |
+
iface = gr.Interface(
|
| 22 |
+
fn=tts_tibetan,
|
| 23 |
+
inputs=gr.Textbox(label="Enter Tibetan text"),
|
| 24 |
+
outputs=gr.Audio(label="Generated Speech", type="file"),
|
| 25 |
+
title="Tibetan MMS-TTS",
|
| 26 |
+
description="Open-source Tibetan text-to-speech using Facebook MMS-TTS."
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
if __name__ == "__main__":
|
| 30 |
+
iface.launch()
|