import gradio as gr import edge_tts import asyncio from gtts import gTTS import os # Dictionary to map language names to their corresponding Edge TTS voices LANGUAGE_VOICES = { 'English-Jenny (Female)': 'en-US-JennyNeural', 'English-Guy (Male)': 'en-US-GuyNeural', # Add more voices as needed } def gtts_tts(input_text, lang): try: tts = gTTS(text=input_text, lang=lang) filename = "output.mp3" tts.save(filename) return filename except Exception as e: return str(e) async def edge_tts_tts(input_text, voice): try: communicate = edge_tts.Communicate(input_text, voice) filename = "output.mp3" await communicate.save(filename) return filename except Exception as e: return str(e) def gtts_service(text, language): return gtts_tts(text, language) def edge_tts_service(text, voice): return asyncio.run(edge_tts_tts(text, voice)) with gr.Blocks() as demo: gr.Markdown(" # GTTS X EDGE-TTS") with gr.Tabs(): with gr.TabItem("gTTS"): with gr.Column(): gtts_language = gr.Dropdown(label="Language", choices=["id", "ms", "en", "es", "fr", "ko", "ja", "de"], value="en") gtts_text_input = gr.Textbox(label="Text to Synthesize") gtts_output_audio = gr.Audio(label="Output Audio") gtts_submit_button = gr.Button("Synthesize") gtts_submit_button.click(gtts_service, inputs=[gtts_text_input, gtts_language], outputs=gtts_output_audio) with gr.TabItem("Edge TTS"): with gr.Column(): edge_language = gr.Dropdown(label="Language and Voice", choices=list(LANGUAGE_VOICES.keys()), value="English-Jenny (Female)") edge_text_input = gr.Textbox(label="Text to Synthesize") edge_output_audio = gr.Audio(label="Output Audio") edge_submit_button = gr.Button("Synthesize") edge_submit_button.click(edge_tts_service, inputs=[edge_text_input, edge_language], outputs=edge_output_audio) demo.launch()