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