Spaces:
Sleeping
Sleeping
| import tkinter as tk | |
| from tkinter import messagebox, ttk | |
| import threading | |
| import os | |
| import asyncio | |
| import edge_tts | |
| from playsound3 import playsound | |
| os.makedirs("tts_outputs", exist_ok=True) | |
| VOICE_DATA = { | |
| "Arabic - Zariyah": "ar-SA-ZariyahNeural", | |
| "Arabic - Hamed": "ar-SA-HamedNeural", | |
| "English (US) - Guy": "en-US-GuyNeural", | |
| "English (US) - Ava": "en-US-AvaNeural", | |
| "English (UK) - Sonia": "en-GB-SoniaNeural", | |
| "English (UK) - Ryan": "en-GB-RyanNeural", | |
| "German (Germany) - Katja": "de-DE-KatjaNeural", | |
| "German (Germany) - Conrad": "de-DE-ConradNeural", | |
| "Spanish (Spain) - Elvira": "es-ES-ElviraNeural", | |
| "Spanish (Spain) - Alvaro": "es-ES-AlvaroNeural", | |
| "Hindi (India) - Swara": "hi-IN-SwaraNeural", | |
| "Hindi (India) - Madhur": "hi-IN-MadhurNeural", | |
| "Turkish (Turkey) - Emel": "tr-TR-EmelNeural", | |
| "Turkish (Turkey) - Ahmet": "tr-TR-AhmetNeural", | |
| "Russian (Russia) - Svetlana": "ru-RU-SvetlanaNeural", | |
| "Russian (Russia) - Dmitry": "ru-RU-DmitryNeural", | |
| } | |
| class EdgeTTSApp: | |
| def __init__(self, root): | |
| self.root = root | |
| self.root.title("Advanced Edge TTS - Professional") | |
| self.root.geometry("650x650") | |
| self.root.configure(bg="#f2f4f7") | |
| self.root.resizable(False, False) | |
| self.setup_ui() | |
| def setup_ui(self): | |
| title_label = tk.Label( | |
| self.root, text="Edge-TTS Voice Generator", | |
| font=("Arial", 20, "bold"), fg="#1A73E8", bg="#f2f4f7" | |
| ) | |
| title_label.pack(pady=20) | |
| tk.Label(self.root, text="Enter your text below:", font=("Arial", 11, "bold"), bg="#f2f4f7").pack(anchor="w", padx=40) | |
| self.text_input = tk.Text(self.root, height=10, width=70, font=("Arial", 11), relief="solid", bd=1) | |
| self.text_input.pack(pady=10, padx=40) | |
| settings_frame = tk.Frame(self.root, bg="#f2f4f7") | |
| settings_frame.pack(pady=10, fill="x", padx=40) | |
| tk.Label(settings_frame, text="Select Voice:", font=("Arial", 10, "bold"), bg="#f2f4f7").grid(row=0, column=0, sticky="w") | |
| self.voice_var = tk.StringVar(value="Arabic (Egypt) - Salma") | |
| self.voice_menu = ttk.Combobox(settings_frame, textvariable=self.voice_var, values=list(VOICE_DATA.keys()), state="readonly", width=30) | |
| self.voice_menu.grid(row=1, column=0, pady=5, padx=(0, 20)) | |
| tk.Label(settings_frame, text="Speed (Rate):", font=("Arial", 10, "bold"), bg="#f2f4f7").grid(row=0, column=1, sticky="w") | |
| self.speed_var = tk.StringVar(value="+0%") | |
| self.speed_menu = ttk.Combobox(settings_frame, textvariable=self.speed_var, values=["-50%", "-25%", "+0%", "+25%", "+50%"], state="readonly", width=10) | |
| self.speed_menu.grid(row=1, column=1, pady=5) | |
| self.convert_button = tk.Button( | |
| self.root, text="Generate & Play Speech", | |
| command=self.start_conversion, | |
| font=("Arial", 13, "bold"), bg="#4CAF50", fg="white", | |
| padx=30, pady=12, relief="raised", cursor="hand2" | |
| ) | |
| self.convert_button.pack(pady=30) | |
| footer = tk.Label( | |
| self.root, text="Free Unlimited Neural TTS | No API Key Required", | |
| font=("Arial", 9, "italic"), fg="#777", bg="#f2f4f7" | |
| ) | |
| footer.pack(side="bottom", pady=20) | |
| async def _generate_audio_task(self, text, voice, rate, output_path): | |
| communicate = edge_tts.Communicate(text, voice, rate=rate) | |
| await communicate.save(output_path) | |
| def process_conversion(self): | |
| text = self.text_input.get("1.0", tk.END).strip() | |
| if not text: | |
| messagebox.showwarning("Warning", "Please enter some text first!") | |
| return | |
| selected_voice_name = self.voice_var.get() | |
| voice_id = VOICE_DATA[selected_voice_name] | |
| speed = self.speed_var.get() | |
| output_path = os.path.join("tts_outputs", "final_output.mp3") | |
| try: | |
| asyncio.run(self._generate_audio_task(text, voice_id, speed, output_path)) | |
| playsound(output_path) | |
| messagebox.showinfo("Success", f"Audio generated successfully using {selected_voice_name}!") | |
| except Exception as e: | |
| messagebox.showerror("Error", f"An error occurred: {str(e)}") | |
| def start_conversion(self): | |
| threading.Thread(target=self.process_conversion, daemon=True).start() | |
| if __name__ == "__main__": | |
| root = tk.Tk() | |
| app = EdgeTTSApp(root) | |
| root.mainloop() |