|
import gradio as gr |
|
from ttsmms import download, TTS |
|
from langdetect import detect |
|
|
|
|
|
swahili_dir = download("swh", "./data/swahili") |
|
english_dir = download("eng", "./data/english") |
|
|
|
swahili_tts = TTS(swahili_dir) |
|
english_tts = TTS(english_dir) |
|
|
|
|
|
def text_to_speech(text): |
|
lang = detect(text) |
|
wav_path = "./output.wav" |
|
|
|
if lang == "sw": |
|
swahili_tts.synthesis(text, wav_path=wav_path) |
|
else: |
|
english_tts.synthesis(text, wav_path=wav_path) |
|
|
|
return wav_path |
|
|
|
|
|
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() |
|
|