Spaces:
Sleeping
Sleeping
Update edge-tts.py
Browse files- edge-tts.py +98 -96
edge-tts.py
CHANGED
|
@@ -1,97 +1,99 @@
|
|
| 1 |
-
import tkinter as tk
|
| 2 |
-
from tkinter import messagebox, ttk
|
| 3 |
-
import threading
|
| 4 |
-
import os
|
| 5 |
-
import asyncio
|
| 6 |
-
import edge_tts
|
| 7 |
-
from playsound3 import playsound
|
| 8 |
-
|
| 9 |
-
os.makedirs("tts_outputs", exist_ok=True)
|
| 10 |
-
|
| 11 |
-
VOICE_DATA = {
|
| 12 |
-
"Arabic (Egypt) - Salma": "ar-EG-SalmaNeural",
|
| 13 |
-
"Arabic (Egypt) - Shakir": "ar-EG-ShakirNeural",
|
| 14 |
-
"Arabic (Saudi) - Zariyah": "ar-SA-ZariyahNeural",
|
| 15 |
-
"
|
| 16 |
-
"English (US) -
|
| 17 |
-
"English (
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
self.root
|
| 25 |
-
self.root.
|
| 26 |
-
self.root.
|
| 27 |
-
self.
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
self.
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
self.
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
self.
|
| 52 |
-
|
| 53 |
-
self.
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
| 97 |
root.mainloop()
|
|
|
|
| 1 |
+
import tkinter as tk
|
| 2 |
+
from tkinter import messagebox, ttk
|
| 3 |
+
import threading
|
| 4 |
+
import os
|
| 5 |
+
import asyncio
|
| 6 |
+
import edge_tts
|
| 7 |
+
from playsound3 import playsound
|
| 8 |
+
|
| 9 |
+
os.makedirs("tts_outputs", exist_ok=True)
|
| 10 |
+
|
| 11 |
+
VOICE_DATA = {
|
| 12 |
+
"Arabic (Egypt) - Salma": "ar-EG-SalmaNeural",
|
| 13 |
+
"Arabic (Egypt) - Shakir": "ar-EG-ShakirNeural",
|
| 14 |
+
"Arabic (Saudi) - Zariyah": "ar-SA-ZariyahNeural",
|
| 15 |
+
"Arabic (Saudi) - Hamed": "ar-SA-HamedNeural",
|
| 16 |
+
"English (US) - Guy": "en-US-GuyNeural",
|
| 17 |
+
"English (US) - Ava": "en-US-AvaNeural",
|
| 18 |
+
"English (UK) - Sonia": "en-GB-SoniaNeural",
|
| 19 |
+
"English (UK) - Ryan": "en-GB-RyanNeural",
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
class EdgeTTSApp:
|
| 23 |
+
def __init__(self, root):
|
| 24 |
+
self.root = root
|
| 25 |
+
self.root.title("Advanced Edge TTS - Professional")
|
| 26 |
+
self.root.geometry("650x650")
|
| 27 |
+
self.root.configure(bg="#f2f4f7")
|
| 28 |
+
self.root.resizable(False, False)
|
| 29 |
+
self.setup_ui()
|
| 30 |
+
|
| 31 |
+
def setup_ui(self):
|
| 32 |
+
title_label = tk.Label(
|
| 33 |
+
self.root, text="Edge-TTS Voice Generator",
|
| 34 |
+
font=("Arial", 20, "bold"), fg="#1A73E8", bg="#f2f4f7"
|
| 35 |
+
)
|
| 36 |
+
title_label.pack(pady=20)
|
| 37 |
+
|
| 38 |
+
tk.Label(self.root, text="Enter your text below:", font=("Arial", 11, "bold"), bg="#f2f4f7").pack(anchor="w", padx=40)
|
| 39 |
+
self.text_input = tk.Text(self.root, height=10, width=70, font=("Arial", 11), relief="solid", bd=1)
|
| 40 |
+
self.text_input.pack(pady=10, padx=40)
|
| 41 |
+
|
| 42 |
+
settings_frame = tk.Frame(self.root, bg="#f2f4f7")
|
| 43 |
+
settings_frame.pack(pady=10, fill="x", padx=40)
|
| 44 |
+
|
| 45 |
+
tk.Label(settings_frame, text="Select Voice:", font=("Arial", 10, "bold"), bg="#f2f4f7").grid(row=0, column=0, sticky="w")
|
| 46 |
+
self.voice_var = tk.StringVar(value="Arabic (Egypt) - Salma")
|
| 47 |
+
self.voice_menu = ttk.Combobox(settings_frame, textvariable=self.voice_var, values=list(VOICE_DATA.keys()), state="readonly", width=30)
|
| 48 |
+
self.voice_menu.grid(row=1, column=0, pady=5, padx=(0, 20))
|
| 49 |
+
|
| 50 |
+
tk.Label(settings_frame, text="Speed (Rate):", font=("Arial", 10, "bold"), bg="#f2f4f7").grid(row=0, column=1, sticky="w")
|
| 51 |
+
self.speed_var = tk.StringVar(value="+0%")
|
| 52 |
+
self.speed_menu = ttk.Combobox(settings_frame, textvariable=self.speed_var, values=["-50%", "-25%", "+0%", "+25%", "+50%"], state="readonly", width=10)
|
| 53 |
+
self.speed_menu.grid(row=1, column=1, pady=5)
|
| 54 |
+
|
| 55 |
+
self.convert_button = tk.Button(
|
| 56 |
+
self.root, text="Generate & Play Speech",
|
| 57 |
+
command=self.start_conversion,
|
| 58 |
+
font=("Arial", 13, "bold"), bg="#4CAF50", fg="white",
|
| 59 |
+
padx=30, pady=12, relief="raised", cursor="hand2"
|
| 60 |
+
)
|
| 61 |
+
self.convert_button.pack(pady=30)
|
| 62 |
+
|
| 63 |
+
footer = tk.Label(
|
| 64 |
+
self.root, text="Free Unlimited Neural TTS | No API Key Required",
|
| 65 |
+
font=("Arial", 9, "italic"), fg="#777", bg="#f2f4f7"
|
| 66 |
+
)
|
| 67 |
+
footer.pack(side="bottom", pady=20)
|
| 68 |
+
|
| 69 |
+
async def _generate_audio_task(self, text, voice, rate, output_path):
|
| 70 |
+
communicate = edge_tts.Communicate(text, voice, rate=rate)
|
| 71 |
+
await communicate.save(output_path)
|
| 72 |
+
|
| 73 |
+
def process_conversion(self):
|
| 74 |
+
text = self.text_input.get("1.0", tk.END).strip()
|
| 75 |
+
if not text:
|
| 76 |
+
messagebox.showwarning("Warning", "Please enter some text first!")
|
| 77 |
+
return
|
| 78 |
+
|
| 79 |
+
selected_voice_name = self.voice_var.get()
|
| 80 |
+
voice_id = VOICE_DATA[selected_voice_name]
|
| 81 |
+
speed = self.speed_var.get()
|
| 82 |
+
|
| 83 |
+
output_path = os.path.join("tts_outputs", "final_output.mp3")
|
| 84 |
+
|
| 85 |
+
try:
|
| 86 |
+
asyncio.run(self._generate_audio_task(text, voice_id, speed, output_path))
|
| 87 |
+
playsound(output_path)
|
| 88 |
+
messagebox.showinfo("Success", f"Audio generated successfully using {selected_voice_name}!")
|
| 89 |
+
|
| 90 |
+
except Exception as e:
|
| 91 |
+
messagebox.showerror("Error", f"An error occurred: {str(e)}")
|
| 92 |
+
|
| 93 |
+
def start_conversion(self):
|
| 94 |
+
threading.Thread(target=self.process_conversion, daemon=True).start()
|
| 95 |
+
|
| 96 |
+
if __name__ == "__main__":
|
| 97 |
+
root = tk.Tk()
|
| 98 |
+
app = EdgeTTSApp(root)
|
| 99 |
root.mainloop()
|