This commit is contained in:
SevaSk 2023-05-12 23:01:36 -04:00
parent d58f5550fa
commit 9e3aa3685d
2 changed files with 25 additions and 16 deletions

View File

@ -104,3 +104,8 @@ class AudioTranscriber:
key=lambda x: x[1], reverse=True)) key=lambda x: x[1], reverse=True))
combined_transcript = combined_transcript[:MAX_PHRASES] combined_transcript = combined_transcript[:MAX_PHRASES]
return "".join([t[0] for t in combined_transcript]) return "".join([t[0] for t in combined_transcript])
def clear_transcript_data(self):
self.transcript_data["You"].clear()
self.transcript_data["Speaker"].clear()

32
main.py
View File

@ -12,36 +12,32 @@ def write_in_textbox(textbox, text):
def update_transcript_UI(transcriber, textbox): def update_transcript_UI(transcriber, textbox):
transcript_string = transcriber.get_transcript() transcript_string = transcriber.get_transcript()
textbox.delete("0.0", "end") write_in_textbox(textbox, transcript_string)
textbox.insert("0.0", transcript_string)
textbox.after(300, update_transcript_UI, transcriber, textbox) textbox.after(300, update_transcript_UI, transcriber, textbox)
def update_response_UI(responder, textbox, update_interval_slider_label, update_interval_slider): def update_response_UI(responder, textbox, update_interval_slider_label, update_interval_slider):
response = responder.response response = responder.response
textbox.configure(state="normal") textbox.configure(state="normal")
textbox.delete("0.0", "end") write_in_textbox(textbox, response)
textbox.insert("0.0", response)
textbox.configure(state="disabled") textbox.configure(state="disabled")
update_interval = int(update_interval_slider.get())
update_interval = int(update_interval_slider.get())
responder.update_response_interval(update_interval) responder.update_response_interval(update_interval)
update_interval_slider_label.configure(text=f"Update interval: {update_interval} seconds") update_interval_slider_label.configure(text=f"Update interval: {update_interval} seconds")
textbox.after(300, update_response_UI, responder, textbox, update_interval_slider_label, update_interval_slider) textbox.after(300, update_response_UI, responder, textbox, update_interval_slider_label, update_interval_slider)
def clear_transcript_data(transcriber): def clear_transcript(transcriber):
transcriber.mic_transcript_data.clear() transcriber.clear_transcript_data()
transcriber.speaker_transcript_data.clear()
if __name__ == "__main__":
def create_ui_components(root):
ctk.set_appearance_mode("dark") ctk.set_appearance_mode("dark")
ctk.set_default_color_theme("dark-blue") ctk.set_default_color_theme("dark-blue")
root = ctk.CTk()
root.title("Ecoute") root.title("Ecoute")
root.configure(bg='#252422') root.configure(bg='#252422')
root.geometry("1000x600") root.geometry("1000x600")
font_size = 20 font_size = 20
transcript_textbox = ctk.CTkTextbox(root, width=300, font=("Arial", font_size), text_color='#FFFCF2', wrap="word") transcript_textbox = ctk.CTkTextbox(root, width=300, font=("Arial", font_size), text_color='#FFFCF2', wrap="word")
@ -50,17 +46,22 @@ if __name__ == "__main__":
response_textbox = ctk.CTkTextbox(root, width=300, font=("Arial", font_size), text_color='#639cdc', wrap="word") response_textbox = ctk.CTkTextbox(root, width=300, font=("Arial", font_size), text_color='#639cdc', wrap="word")
response_textbox.grid(row=0, column=1, padx=10, pady=20, sticky="nsew") response_textbox.grid(row=0, column=1, padx=10, pady=20, sticky="nsew")
# empty label, necessary for proper grid spacing
update_interval_slider_label = ctk.CTkLabel(root, text=f"", font=("Arial", 12), text_color="#FFFCF2") update_interval_slider_label = ctk.CTkLabel(root, text=f"", font=("Arial", 12), text_color="#FFFCF2")
update_interval_slider_label.grid(row=1, column=1, padx=10, pady=3, sticky="nsew") update_interval_slider_label.grid(row=1, column=1, padx=10, pady=3, sticky="nsew")
# Create the update interval slider
update_interval_slider = ctk.CTkSlider(root, from_=1, to=10, width=300, height=20, number_of_steps=9) update_interval_slider = ctk.CTkSlider(root, from_=1, to=10, width=300, height=20, number_of_steps=9)
update_interval_slider.set(2) update_interval_slider.set(2)
update_interval_slider.grid(row=3, column=1, padx=10, pady=10, sticky="nsew") update_interval_slider.grid(row=3, column=1, padx=10, pady=10, sticky="nsew")
update_interval_slider_label = ctk.CTkLabel(root, text=f"Update interval: {update_interval_slider.get()} seconds", font=("Arial", 12), text_color="#FFFCF2") update_interval_slider_label = ctk.CTkLabel(root, text=f"Update interval: {update_interval_slider.get()} seconds", font=("Arial", 12), text_color="#FFFCF2")
update_interval_slider_label.grid(row=2, column=1, padx=10, pady=10, sticky="nsew") update_interval_slider_label.grid(row=2, column=1, padx=10, pady=10, sticky="nsew")
return transcript_textbox, response_textbox, update_interval_slider, update_interval_slider_label
def main():
root = ctk.CTk()
transcript_textbox, response_textbox, update_interval_slider, update_interval_slider_label = create_ui_components(root)
audio_queue = queue.Queue() audio_queue = queue.Queue()
user_audio_recorder = AudioRecorder.DefaultMicRecorder() user_audio_recorder = AudioRecorder.DefaultMicRecorder()
@ -90,10 +91,13 @@ if __name__ == "__main__":
root.grid_columnconfigure(1, weight=1) root.grid_columnconfigure(1, weight=1)
# Add the clear transcript button to the UI # Add the clear transcript button to the UI
clear_transcript_button = ctk.CTkButton(root, text="Clear Transcript", command=lambda: clear_transcript_data(global_transcriber, )) clear_transcript_button = ctk.CTkButton(root, text="Clear Transcript", command=lambda: clear_transcript(global_transcriber, ))
clear_transcript_button.grid(row=1, column=0, padx=10, pady=3, sticky="nsew") clear_transcript_button.grid(row=1, column=0, padx=10, pady=3, sticky="nsew")
update_transcript_UI(global_transcriber, transcript_textbox) update_transcript_UI(global_transcriber, transcript_textbox)
update_response_UI(responder, response_textbox, update_interval_slider_label, update_interval_slider) update_response_UI(responder, response_textbox, update_interval_slider_label, update_interval_slider)
root.mainloop() root.mainloop()
if __name__ == "__main__":
main()