Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import VitsModel, AutoTokenizer
|
| 3 |
+
import torch
|
| 4 |
+
import scipy.io.wavfile
|
| 5 |
+
import tempfile
|
| 6 |
+
|
| 7 |
+
# Load the Somali TTS model
|
| 8 |
+
model = VitsModel.from_pretrained("facebook/mms-tts-som")
|
| 9 |
+
tokenizer = AutoTokenizer.from_pretrained("facebook/mms-tts-som")
|
| 10 |
+
|
| 11 |
+
def somali_text_to_speech(text):
|
| 12 |
+
inputs = tokenizer(text, return_tensors="pt")
|
| 13 |
+
|
| 14 |
+
with torch.no_grad():
|
| 15 |
+
output = model(**inputs)
|
| 16 |
+
|
| 17 |
+
waveform = output.waveform.squeeze().cpu().numpy()
|
| 18 |
+
|
| 19 |
+
# Save waveform to a temporary WAV file
|
| 20 |
+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp:
|
| 21 |
+
scipy.io.wavfile.write(tmp.name, rate=model.config.sampling_rate, data=waveform)
|
| 22 |
+
return tmp.name
|
| 23 |
+
|
| 24 |
+
# Launch Gradio Interface
|
| 25 |
+
gr.Interface(
|
| 26 |
+
fn=somali_text_to_speech,
|
| 27 |
+
inputs=gr.Textbox(label="Enter Somali Text"),
|
| 28 |
+
outputs=gr.Audio(label="Generated Somali Speech"),
|
| 29 |
+
title="Somali Text-to-Speech",
|
| 30 |
+
description="Type Somali text and hear it spoken using Hugging Face's VitsModel."
|
| 31 |
+
).launch(share=True)
|