Speech-recognition / app.py(tts)
Futuresony's picture
Rename app.py to app.py(tts)
a72ba54 verified
raw
history blame contribute delete
988 Bytes
import gradio as gr
from ttsmms import download, TTS
from langdetect import detect
# Download and load TTS models for Swahili and English
swahili_dir = download("swh", "./data/swahili")
english_dir = download("eng", "./data/english") # Ensure an English TTS model is available
swahili_tts = TTS(swahili_dir)
english_tts = TTS(english_dir)
# Function to detect language and generate speech
def text_to_speech(text):
lang = detect(text) # Detect language
wav_path = "./output.wav"
if lang == "sw": # Swahili
swahili_tts.synthesis(text, wav_path=wav_path)
else: # Default to English if not Swahili
english_tts.synthesis(text, wav_path=wav_path)
return wav_path
# Gradio UI
gr.Interface(
fn=text_to_speech,
inputs=gr.Textbox(label="Enter Text"),
outputs=gr.Audio(label="Generated Speech"),
title="Swahili & English Text-to-Speech",
description="Type text and listen to the generated speech in Swahili or English.",
).launch()