From ddf340f87a6e8ff1700242209f6692cc380508ee Mon Sep 17 00:00:00 2001 From: "DHR.Mike" Date: Fri, 12 Dec 2025 06:14:57 -0800 Subject: [PATCH] Update Uptated-Prototype/PiperTTS-GUI-Test.py --- Uptated-Prototype/PiperTTS-GUI-Test.py | 450 +++++-------------------- 1 file changed, 92 insertions(+), 358 deletions(-) diff --git a/Uptated-Prototype/PiperTTS-GUI-Test.py b/Uptated-Prototype/PiperTTS-GUI-Test.py index dcb428f..97b0f85 100644 --- a/Uptated-Prototype/PiperTTS-GUI-Test.py +++ b/Uptated-Prototype/PiperTTS-GUI-Test.py @@ -1,366 +1,100 @@ -from tkinter import * -from tkinter import ttk -from tkinter import filedialog -import atexit -import random -import time +import json -# Start of Code - Start of Tkinter loop -Root_Window = Tk() -Root_Window.title("PiperTTS - Prototype GUI") # Sets the GUI Title +########################## +x = { + "en_GB-alan-low": { + "key": "en_GB-alan-low", + "name": "alan", + "language": { + "code": "en_GB", + "family": "en", + "region": "GB", + "name_native": "English", + "name_english": "English", + "country_english": "Great Britain" + }, + "quality": "low", + "num_speakers": 1, + "speaker_id_map": {}, + "files": { + "en/en_GB/alan/low/en_GB-alan-low.onnx": { + "size_bytes": 63104526, + "md5_digest": "2acae8c79395ab109a7572f0afa61fff" + }, + "en/en_GB/alan/low/en_GB-alan-low.onnx.json": { + "size_bytes": 4170, + "md5_digest": "4c0fa2c6763bf49b343cbb4f655a147b" + }, + "en/en_GB/alan/low/MODEL_CARD": { + "size_bytes": 309, + "md5_digest": "b116c3cbdebac99ade9af03807cb9301" + } + }, + "aliases": [ + "en-gb-alan-low" + ] + }, + "en_GB-alan-medium": { + "key": "en_GB-alan-medium", + "name": "alan", + "language": { + "code": "en_GB", + "family": "en", + "region": "GB", + "name_native": "English", + "name_english": "English", + "country_english": "Great Britain" + }, + "quality": "medium", + "num_speakers": 1, + "speaker_id_map": {}, + "files": { + "en/en_GB/alan/medium/en_GB-alan-medium.onnx": { + "size_bytes": 63201294, + "md5_digest": "8f6b35eeb8ef6269021c6cb6d2414c9b" + }, + "en/en_GB/alan/medium/en_GB-alan-medium.onnx.json": { + "size_bytes": 4888, + "md5_digest": "b11d9afd0a8f5372c42a52fbd6e021d4" + }, + "en/en_GB/alan/medium/MODEL_CARD": { + "size_bytes": 320, + "md5_digest": "24a2232470ca1be071debf53c984666e" + } + }, + "aliases": [] + } +} -# Setting up Window Starting Size and Position (can only be even numbers) -Window_Width = 426 -Window_Height = 576 -# Getting Screen Width and Height -Screen_Width = Root_Window.winfo_screenwidth() -Screen_Height = Root_Window.winfo_screenheight() -# Calculate Center of Screen for the window -Window_PosX = (Screen_Width/2) - (Window_Width/2) -Window_PosY = (Screen_Height/2) - (Window_Height/2) -# Sets the GUI geometry and attempts to centers window on screen -Root_Window.geometry(f'{Window_Width}x{Window_Height}+{int(Window_PosX)}+{int(Window_PosY)}') -#Root_Window.minsize(Window_Width, Window_Height) +# convert into JSON: +y = json.dumps(x) +z = json.loads(y) -# Attempts to create a Input Frame +for voice_id, info in z.items(): + lang = info["language"]["country_english"] + print(lang) + +########################## + +# Attempts to load voices.json try: - Input_Box_Frame = Frame(Root_Window) -except Exception as e: - print(e, type(e)) - print("An exception occurred - when creating input Frame.") -# Attempts to create a Controls Frame -try: - Controls_Box_Frame = Frame(Root_Window) -except Exception as e: - print(e, type(e)) - print("An exception occurred - when creating Controls Frame.") -# Attempts to create a Prefrences Frame -try: - Prefrences_Frame = Frame(Root_Window) -except Exception as e: - print(e, type(e)) - print("An exception occurred - when creating Controls Frame.") -# Attempts to Place Input and Controls frames -try: - Input_Box_Frame.place(x = 0, y = 0, relwidth = 1, relheight = 0.7) - Controls_Box_Frame.place(x = 0, rely = 0.8, relwidth = 1, relheight = 0.7) -except Exception as e: - print(e, type(e)) - print("An exception occurred - when placing Frames.") + with open("voices/voices.json","r") as file: + data = json.load(file) +# Failed at loading voices.json +except FileNotFoundError: + print("Error: The file 'voises.json' was not found.") -# Attempts to create a Input box -try: - Input_Box = Text(Input_Box_Frame, selectbackground="yellow", selectforeground="black", undo=True) - Input_Box.pack(padx=5, pady=5, expand = True, fill = "both") -except Exception as e: - print(e, type(e)) - print("An exception occurred - when creating input box.") +# Create a list for Languages +mylist = [] -# Attempts to create a scrollbar for the Input box -try: - Main_Text_Scrollbar = Scrollbar(Input_Box_Frame, command = Input_Box_Frame.yview) - Input_Box_Frame.configure(yscrollcommand = Main_Text_Scrollbar.set) - Main_Text_Scrollbar.place(relx = 1, rely = 0, relheight = 1, anchor = "ne") -except Exception as e: - print(e, type(e)) - print("An exception occurred - when creating a scroll bar.") +# Appends and formats all the languages to the list +for voice_id, info in z.items(): + #print((f"{info["language"]["name_native"]} ({info["language"]["name_english"]}, {info["language"]["country_english"]})") + mylist.append(f"{info["language"]["name_native"]} ({info["language"]["name_english"]}, {info["language"]["country_english"]})") -# -def PiperTTS_GUI_Play(): - try: - My_Test_Label["text"] = "Playing?" - C_Button_Pause["state"] == "normal" - C_Button_Play["state"] = "disabled" - except Exception as e: - print(e, type(e)) - print("An exception occurred - when pressing Play Button.") +# Removes duplicate languages choices from list +mylist = list(dict.fromkeys(mylist)) -# -def PiperTTS_GUI_Pause(): - try: - My_Test_Label["text"] = "Pause?" - C_Button_Pause["state"] == "disabled" - C_Button_Play["state"] = "normal" - except Exception as e: - print(e, type(e)) - print("An exception occurred - when pressing Pause Button.") - -# -def PiperTTS_GUI_Stop(): - try: - My_Test_Label["text"] = "Stop?" - C_Button_Pause["state"] == "disabled" - C_Button_Play["state"] = "normal" - except Exception as e: - print(e, type(e)) - print("An exception occurred - when pressing Stop Button.") - -# -def PiperTTS_GUI_Previous(): - try: - My_Test_Label["text"] = "Previous?" - except Exception as e: - print(e, type(e)) - print("An exception occurred - when pressing Previous Button.") - -# -def PiperTTS_GUI_Next(): - try: - My_Test_Label["text"] = "Next?" - except Exception as e: - print(e, type(e)) - print("An exception occurred - when pressing Next Button.") - -# -def PiperTTS_GUI_New_File(): - try: - My_Test_Label["text"] = "New File?" - Input_Box.delete("1.0", "end-1c") - except Exception as e: - print(e, type(e)) - print("An exception occurred - when pressing New File Button.") - -# -def PiperTTS_GUI_Get_Selection(): - try: - Selected = Root_Window.selection_get() - if not Selected: - My_Test_Label["text"] = "No text Selected" - else: - Cursor_Position = Input_Box.index(INSERT) - Input_Box.insert(Cursor_Position, Selected) - except Exception as e: - print(e, type(e)) - print("An exception occurred - when grabbing Selection.") - -# -def PiperTTS_GUI_Get_Clipboard(): - try: - Selected = Root_Window.clipboard_get() - if not Selected: - My_Test_Label["text"] = "No text in clipboard" - else: - Cursor_Position = Input_Box.index(INSERT) - Input_Box.insert(Cursor_Position, Selected) - except Exception as e: - print(e, type(e)) - print("An exception occurred - when grabbing Clipboard.") -# -def PiperTTS_GUI_TextFile_Open(): - try: - Root_Window.filename = filedialog.askopenfilename(initialdir = "./",title = "Select file",filetypes = (("Text files","*.txt"),("all files","*.*"))) - if Root_Window.filename: - with open(Root_Window.filename) as f: - Cursor_Position = Input_Box.index(INSERT) - Input_Box.insert(Cursor_Position, f.read()) - #MyTestText = Input_Box.get("1.0","end-1c") - #MyTestText2 = "There are {}, lines".format(len(MyTestText.splitlines())) - #My_Test_Label2["text"] = MyTestText2 - Test_var.set("There are {}, lines".format(len(Input_Box.get("1.0","end-1c").splitlines()))) - else: - print("Canceled file dialog.") - except Exception as e: - print(e, type(e)) - print("An exception occurred - when Opening Text File.") -# -def PiperTTS_GUI_Reverse_Text(): - try: - TempText = Input_Box.get("1.0","end-1c") - Input_Box.delete("1.0", "end-1c") - Input_Box.insert("1.0", TempText[::-1]) - except Exception as e: - print(e, type(e)) - print("An exception occurred - when reversing text.") -# -def PiperTTS_GUI_Randomize_Text(): - try: - start_time = time.time() - TempText = Input_Box.get("1.0","end-1c") - Input_Box.delete("1.0", "end-1c") - TempList = list(TempText) - random.shuffle(TempList) - Input_Box.insert("1.0", ''.join(TempList)) - end_time = time.time() - print(f'Elapsed Time: {end_time - start_time} seconds') - except Exception as e: - print(e, type(e)) - print("An exception occurred - when Randomizing text.") -# -def PiperTTS_GUI_Randomize_Text_2nd(): - try: - start_time = time.time() - TempText = Input_Box.get("1.0","end-1c") - Input_Box.delete("1.0", "end-1c") - Input_Box.insert("1.0", "".join(random.sample(TempText, len(TempText)))) - end_time = time.time() - print(f'Elapsed Time: {end_time - start_time} seconds') - except Exception as e: - print(e, type(e)) - print("An exception occurred - when Randomizing text.") -# -def PiperTTS_GUI_Set_Prefrences(): - try: - Input_Box_Frame.place_forget() - Controls_Box_Frame.place_forget() - Prefrences_Frame.place(x = 0, y = 0, relwidth = 1, relheight = 1) - except Exception as e: - print(e, type(e)) - print("An exception occurred - when Setting prefrences.") - - -''' -# -def PiperTTS_GUI_Clipboard(): - try: - #PiperTTS_GUI_Hide_All_Labels() - My_Label = Label(Controls_Box_Frame, text="Clipboard?").grid(row=3, column=0, columnspan=5) - #global labels = [] - labels.append(My_Label) - except Exception as e: - print(e, type(e)) - print("An exception occurred - when pressing Clipboard Button.") -# Deleting info messages -def PiperTTS_GUI_Hide_All_Labels(): - try: - for label in labels: - label.destroy() - except Exception as e: - print(e, type(e)) - print("An exception occurred - when attempting to hide previous messages.") -''' -# Creating Buttons -#C_Button_Clipboard = Button(Controls_Box_Frame, text="📋", pady=5, padx=5, command=PiperTTS_GUI_Clipboard) -C_Button_Play = Button(Controls_Box_Frame, text="▶", pady=5, padx=5, command=PiperTTS_GUI_Play) -C_Button_Pause = Button(Controls_Box_Frame, text="⏸", pady=5, padx=5, command=PiperTTS_GUI_Pause) -C_Button_Stop = Button(Controls_Box_Frame, text="⏹", pady=5, padx=5, command=PiperTTS_GUI_Stop) -C_Button_previous = Button(Controls_Box_Frame, text="⏮", pady=5, padx=5, command=PiperTTS_GUI_Previous) -C_Button_Next = Button(Controls_Box_Frame, text="⏭", pady=5, padx=5, command=PiperTTS_GUI_Next) - -# Creating a Test Text Label -My_Test_Label = Label(Controls_Box_Frame, text="Test Text?") -My_Test_Label.grid(row=0, column=0, columnspan=4) -# -try: - Test_var = StringVar(value = "0") - Test_var.set("There are {}, lines".format(len(Input_Box.get("1.0","end-1c").splitlines()))) -except Exception as e: - print(e, type(e)) - print("Mkay did not work.") -# -def OnKeyPress(event): - print("Start OnKeyPress") - start_time = time.time() - Test_var.set("There are {}, lines".format(len(Input_Box.get("1.0","end-1c").splitlines()))) - end_time = time.time() - print(f'Elapsed Time: {end_time - start_time} seconds') - print("End OnKeyPress") -# -def OnKeyPress2nd(event): - print("Start OnKeyPress2nd") - start_time = time.time() - Test_var.set("There are {}, displaylines".format(Input_Box.count("1.0", "end", "displaylines"))) - #print("displaylines:", Input_Box.count("1.0", "end", "displaylines")) - #print("lines:", Input_Box.count("1.0", "end", "lines")) - end_time = time.time() - print(f'Elapsed Time: {end_time - start_time} seconds') - print("End OnKeyPress2nd") -# -Input_Box.bind("", OnKeyPress2nd) -Input_Box.bind("", OnKeyPress) - -# -My_Test_Label2 = Label(Controls_Box_Frame, textvariable=Test_var) -#My_Test_Label2["value"] = Test_var -#My_Test_Label2["text"] = MyTestText2 -''' -try: - try: - #MyTestText = Input_Box.get("1.0","end-1c") - #MyTestText2 = "There are {}, lines".format(len(Input_Box.get("1.0","end-1c").splitlines())) - My_Test_Label2["text"] = "There are {}, lines".format(len(Input_Box.get("1.0","end-1c").splitlines())) - except Exception as e: - print(e, type(e)) - print("Fuckup again.") -except Exception as e: - print(e, type(e)) - print("An exception occurred - trying to count like dracula.") -''' -My_Test_Label2.grid(row=2, column=0, columnspan=4) - -# Aligning Buttons to grid -#C_Button_Clipboard.grid(row=1, column=4) -C_Button_Play.grid(row=1, column=0) -C_Button_Pause.grid(row=1, column=1) -C_Button_Stop.grid(row=1, column=2) -C_Button_previous.grid(row=1, column=3) -C_Button_Next.grid(row=1, column=4) - -# Prefrences stuff -GUI_Combobox_1_Label = Label(Prefrences_Frame, text="Language?") -GUI_Combobox_1 = ttk.Combobox(Prefrences_Frame) -GUI_Combobox_2_Label = Label(Prefrences_Frame, text="Voice?") -GUI_Combobox_2 = ttk.Combobox(Prefrences_Frame) -GUI_Spinbox_1_Label = Label(Prefrences_Frame, text="volume?") -GUI_Spinbox_1 = ttk.Spinbox(Prefrences_Frame, from_ = 1, to = 100) -GUI_Spinbox_2_Label = Label(Prefrences_Frame, text="length_scale?") -GUI_Spinbox_2 = ttk.Spinbox(Prefrences_Frame, from_ = 1.0, to = 2.0) -GUI_Spinbox_3_Label = Label(Prefrences_Frame, text="noise_scale?") -GUI_Spinbox_3 = ttk.Spinbox(Prefrences_Frame, from_ = 1.0, to = 2.0) -GUI_Spinbox_4_Label = Label(Prefrences_Frame, text="noise_w_scale?") -GUI_Spinbox_4 = ttk.Spinbox(Prefrences_Frame, from_ = 1.0, to = 2.0) -GUI_Checkbutton_1 = ttk.Checkbutton(Prefrences_Frame, text="normalize_audio?") -# Prefrences placement -GUI_Combobox_1_Label.pack(side = LEFT) -GUI_Combobox_1.pack(side = LEFT) -GUI_Combobox_2_Label.pack(side = LEFT) -GUI_Combobox_2.pack(side = LEFT) -GUI_Spinbox_1_Label.pack() -GUI_Spinbox_1.pack() -GUI_Spinbox_2_Label.pack() -GUI_Spinbox_2.pack() -GUI_Spinbox_3_Label.pack() -GUI_Spinbox_3.pack() -GUI_Spinbox_4_Label.pack() -GUI_Spinbox_4.pack() -GUI_Checkbutton_1.pack() - -#Creating Toolbar menu -Root_Toolbar = Menu(Root_Window) -Root_Window.configure(menu=Root_Toolbar) -#Creating File menu for Toolbar -File_Toolbar = Menu(Root_Toolbar, tearoff=False) -Root_Toolbar.add_cascade(label="File", menu=File_Toolbar) -File_Toolbar.add_command(label="New", command=PiperTTS_GUI_New_File) -File_Toolbar.add_command(label="Open", command=PiperTTS_GUI_TextFile_Open) -File_Toolbar.add_command(label="Save as Wave") -File_Toolbar.add_separator() -File_Toolbar.add_command(label="Exit", command=Root_Window.quit) -#Creating Playback menu for Toolbar -Playback_Toolbar = Menu(Root_Toolbar, tearoff=False) -Root_Toolbar.add_cascade(label="Playback", menu=Playback_Toolbar) -Playback_Toolbar.add_command(label="▶ Play", command=PiperTTS_GUI_Play) -Playback_Toolbar.add_command(label="⏸ Pause", command=PiperTTS_GUI_Pause) -Playback_Toolbar.add_command(label="⏹ Stop", command=PiperTTS_GUI_Stop) -Playback_Toolbar.add_command(label="⏮ Previous", command=PiperTTS_GUI_Previous) -Playback_Toolbar.add_command(label="⏭ Next", command=PiperTTS_GUI_Next) -#Creating Tools menu for Toolbar -Tools_Toolbar = Menu(Root_Toolbar, tearoff=False) -Root_Toolbar.add_cascade(label="Tools", menu=Tools_Toolbar) -Tools_Toolbar.add_command(label="Insert Selection", command=PiperTTS_GUI_Get_Selection) -Tools_Toolbar.add_command(label="Insert Clipboard", command=PiperTTS_GUI_Get_Clipboard) -Tools_Toolbar.add_separator() -Tools_Toolbar.add_command(label="Randomize Text", command=PiperTTS_GUI_Randomize_Text) -Tools_Toolbar.add_command(label="Randomize Text 2nd", command=PiperTTS_GUI_Randomize_Text_2nd) -Tools_Toolbar.add_command(label="Reverse Text", command=PiperTTS_GUI_Reverse_Text) -Tools_Toolbar.add_separator() -Tools_Toolbar.add_command(label="Prefrences", command=PiperTTS_GUI_Set_Prefrences) - -# End of Code - Emd of Tkinter loop -Root_Window.mainloop() - -# Function called on Exit -def Registered_Exit(): - print("Goodbye!?") - -# Regestering Exit -atexit.register(Registered_Exit) \ No newline at end of file +# Prints avalible list +for count in mylist: + print(count)