Shanulhaq's picture
Create app.py
a03b7f2 verified
raw
history blame
787 Bytes
import gradio as gr
from TTS.api import TTS
# Initialize the TTS model
tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC", progress_bar=False, gpu=False)
def text_to_speech(text):
# Generate speech from text
audio_path = tts.tts_to_file(text=text, file_path="output.wav")
# Read the audio file
with open("output.wav", "rb") as f:
audio_bytes = f.read()
return audio_bytes
# Create Gradio interface
interface = gr.Interface(
fn=text_to_speech,
inputs=gr.inputs.Textbox(lines=5, placeholder="Enter text here..."),
outputs=gr.outputs.Audio(type="file"),
title="AI-Powered Text-to-Speech Converter",
description="Convert text to speech using AI models.",
)
# Launch the interface
if __name__ == "__main__":
interface.launch()