Skip to content

Commit

Permalink
UI changes into a single button
Browse files Browse the repository at this point in the history
  • Loading branch information
Adarsha-gg committed Sep 2, 2023
1 parent bff4eac commit ab7a0b8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 32 deletions.
3 changes: 1 addition & 2 deletions GlobalVars.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ class TranscriptionGlobals(Singleton.Singleton):
# Global for determining whether to seek responses from openAI API
freeze_state: list = None
freeze_button: ctk.CTkButton = None
microphone_button: ctk.CTkButton = None
speaker_button: ctk.CTkButton = None
menu_button: ctk.CTkOptionMenu = None
api_key: str = None
filemenu: tk.Menu = None
response_textbox: ctk.CTkTextbox = None
Expand Down
31 changes: 16 additions & 15 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def main():
global_vars = GlobalVars.TranscriptionGlobals()

global_vars = GlobalVars.TranscriptionGlobals(key=config["OpenAI"]["api_key"])

# Initiate logging
log_listener = app_logging.initiate_log(config=config)

Expand All @@ -99,14 +99,6 @@ def main():
print('[INFO] Override default speaker with device specified on command line.')
global_vars.speaker_audio_recorder.set_device(index=args.speaker_device_index)

if args.disable_mic:
print('[INFO] Disabling Microphone')
global_vars.user_audio_recorder.disable()

if args.disable_speaker:
print('[INFO] Disabling Speaker')
global_vars.speaker_audio_recorder.disable()

try:
subprocess.run(["ffmpeg", "-version"],
stdout=subprocess.DEVNULL,
Expand Down Expand Up @@ -136,6 +128,7 @@ def main():
model = TranscriberModels.get_model(args.api, model=args.model)

root = ctk.CTk()
ui_cb = ui.ui_callbacks()
ui_components = ui.create_ui_components(root)
transcript_textbox = ui_components[0]
global_vars.response_textbox = ui_components[1]
Expand All @@ -146,8 +139,7 @@ def main():
global_vars.filemenu = ui_components[6]
response_now_button = ui_components[7]
read_response_now_button = ui_components[8]
global_vars.microphone_button = ui_components[9]
global_vars.speaker_button = ui_components[10]
global_vars.menu_button = ui_components[9]
global_vars.user_audio_recorder.record_into_queue(global_vars.audio_queue)

time.sleep(2)
Expand All @@ -156,6 +148,16 @@ def main():
global_vars.freeze_state = [True]
convo = conversation.Conversation()

if args.disable_mic:
print('[INFO] Disabling Microphone')
ui_cb.menu_value()
global_vars.user_audio_recorder.disable()

if args.disable_speaker:
print('[INFO] Disabling Speaker')
ui_cb.menu_value()
global_vars.speaker_audio_recorder.disable()

# Transcribe and Respond threads, both work on the same instance of the AudioTranscriber class
global_vars.transcriber = AudioTranscriber(global_vars.user_audio_recorder.source,
global_vars.speaker_audio_recorder.source,
Expand Down Expand Up @@ -190,16 +192,15 @@ def main():
root.grid_columnconfigure(0, weight=2)
root.grid_columnconfigure(1, weight=1)

ui_cb = ui.ui_callbacks()

global_vars.freeze_button.configure(command=ui_cb.freeze_unfreeze)
response_now_button.configure(command=ui_cb.update_response_ui_now)
read_response_now_button.configure(command=ui_cb.update_response_ui_and_read_now)
label_text = f'Update Response interval: {update_interval_slider.get()} seconds'
update_interval_slider_label.configure(text=label_text)
global_vars.microphone_button.configure(command=ui_cb.enable_disable_microphone)
global_vars.speaker_button.configure(command=ui_cb.enable_disable_speaker)
global_vars.menu_button.configure(command=ui_cb.check)
lang_combobox.configure(command=model.change_lang)

ui.update_transcript_ui(global_vars.transcriber, transcript_textbox)
ui.update_response_ui(global_vars.responder, global_vars.response_textbox,
update_interval_slider_label, update_interval_slider,
Expand Down
40 changes: 25 additions & 15 deletions ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,31 @@ def freeze_unfreeze(self):
root_logger.info(ui_callbacks.freeze_unfreeze.__name__)
self.global_vars.freeze_state[0] = not self.global_vars.freeze_state[0] # Invert the state
self.global_vars.freeze_button.configure(
text="Suggest Responses Continuously" if self.global_vars.freeze_state[0] else "Do Not Suggest Responses Continuously"
value="Suggest Responses Continuously" if self.global_vars.freeze_state[0] else "Do Not Suggest Responses Continuously"
)
def enable_disable_speaker(self):
self.global_vars.speaker_audio_recorder.enabled = not self.global_vars.speaker_audio_recorder.enabled
self.global_vars.speaker_button.configure(
text="Speaker enabled" if self.global_vars.speaker_audio_recorder.enabled else "Speaker disabled"

def menu_value(self):
self.global_vars.menu_button.configure(
values=("Disable Speaker" if self.global_vars.speaker_audio_recorder.enabled else "Enable Speaker",
"Disable Microphone" if self.global_vars.user_audio_recorder.enabled else "Enable Microphone"
)
)
self.global_vars.menu_button.set("Menu")

def check(self,value):
if value == "Disable Speaker" or value == "Enable Speaker" :
self.enable_disable_speaker()
elif value == "Disable Microphone" or value == "Enable Microphone":
self.enable_disable_microphone()

def enable_disable_speaker(self):
self.global_vars.speaker_audio_recorder.enabled = not self.global_vars.speaker_audio_recorder.enabled
self.menu_value()

def enable_disable_microphone(self):
self.global_vars.user_audio_recorder.enabled = not self.global_vars.user_audio_recorder.enabled
self.global_vars.microphone_button.configure(
text="Microphone enabled" if self.global_vars.user_audio_recorder.enabled else "Microphone disabled"
)
self.menu_value()


def update_response_ui_now(self):
"""Get response from LLM right away
Expand Down Expand Up @@ -230,16 +242,14 @@ def create_ui_components(root):
update_interval_slider.grid(row=2, column=0, padx=10, pady=10, sticky="nsew")

lang_combobox = ctk.CTkOptionMenu(root,width=15, values=list(LANGUAGES_DICT.values()))
lang_combobox.grid(row=3, column=0,ipadx = 60, sticky="w")

microphone_button = ctk.CTkButton(root,width=15, text="Microphone enabled", command=None )
microphone_button.grid(row=3, column = 0,ipadx= 50, sticky="e")
lang_combobox.grid(row=3, column=0, ipadx=60, padx=10, sticky="wn")

speaker_button = ctk.CTkButton(root,width=15, text=" Speaker enabled", command=None )
speaker_button.grid(row=3, column = 0,ipadx= 60,)
menu_button = ctk.CTkOptionMenu(root,values=["Disable Microphone", "Disable Speaker"], command=None)
menu_button.set("Menu")
menu_button.grid(row=3, column=0, ipadx=60, sticky="ne")

# Order of returned components is important.
# Add new components to the end
return [transcript_textbox, response_textbox, update_interval_slider,
update_interval_slider_label, freeze_button, lang_combobox,
filemenu, response_now_button, read_response_now_button, microphone_button, speaker_button]
filemenu, response_now_button, read_response_now_button, menu_button]

0 comments on commit ab7a0b8

Please sign in to comment.