import gradio as gr from gtts import gTTS from io import BytesIO def text_to_speech(text, language="en"): """ Convert text to speech using gTTS and return the audio file. """ try: if not text.strip(): return "Error: Please enter valid text.", None # Generate the speech using gTTS tts = gTTS(text=text, lang=language) audio_file = BytesIO() tts.write_to_fp(audio_file) audio_file.seek(0) return "Text-to-Speech conversion successful!", audio_file except Exception as e: return f"Error: {str(e)}", None # HTML content with animations, styling, and JavaScript html_content = """ AI Text-to-Speech Web App

AI Text-to-Speech Web App

""" # Gradio interface setup for integrating frontend def gradio_interface(): return gr.HTML(html_content) interface = gr.Interface(fn=text_to_speech, inputs=[gr.Textbox(), gr.Dropdown()], outputs=[gr.Textbox(), gr.Audio()]) interface.launch()