Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import librosa
|
3 |
+
import sounddevice as sd
|
4 |
+
import numpy as np
|
5 |
+
from ttsmms import download, TTS
|
6 |
+
|
7 |
+
# Download and load the Swahili TTS model
|
8 |
+
dir_path = download("swh", "./data") # Change "swh" to another language if needed
|
9 |
+
tts = TTS(dir_path)
|
10 |
+
|
11 |
+
# Function to generate speech from text
|
12 |
+
def text_to_speech(text):
|
13 |
+
result = tts.synthesis(text)
|
14 |
+
audio = result["x"]
|
15 |
+
sample_rate = result["sampling_rate"]
|
16 |
+
|
17 |
+
# Play generated speech in real-time
|
18 |
+
sd.play(audio, samplerate=sample_rate)
|
19 |
+
sd.wait()
|
20 |
+
|
21 |
+
return audio, sample_rate
|
22 |
+
|
23 |
+
# Gradio UI for TTS
|
24 |
+
gr.Interface(
|
25 |
+
fn=text_to_speech,
|
26 |
+
inputs=gr.Text(label="Enter Text"),
|
27 |
+
outputs=gr.Audio(label="Generated Speech"),
|
28 |
+
title="Swahili Text-to-Speech",
|
29 |
+
description="Type text and listen to the generated Swahili speech.",
|
30 |
+
).launch()
|