From e2c995acec6a791640feae6eb1789471dc7d0518 Mon Sep 17 00:00:00 2001 From: Randy Mackay Date: Tue, 6 Aug 2024 15:19:46 +0900 Subject: [PATCH] chat: pass stop recording to voice-to-text --- .../mavproxy_chat/chat_voice_to_text.py | 2 ++ MAVProxy/modules/mavproxy_chat/chat_window.py | 19 +++++++------------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/MAVProxy/modules/mavproxy_chat/chat_voice_to_text.py b/MAVProxy/modules/mavproxy_chat/chat_voice_to_text.py index 50a998e785..d03076b882 100644 --- a/MAVProxy/modules/mavproxy_chat/chat_voice_to_text.py +++ b/MAVProxy/modules/mavproxy_chat/chat_voice_to_text.py @@ -60,6 +60,7 @@ def record_audio(self): self.stop_recording = False # record until specified time + print("chat: voice-to-text started recording!") frames = [] while curr_time < time_stop and not self.stop_recording: data = stream.read(1024) @@ -82,6 +83,7 @@ def record_audio(self): # stop recording audio def stop_record_audio(self): + print("chat: voice-to-text will stop recording!") self.stop_recording = True # convert audio to text diff --git a/MAVProxy/modules/mavproxy_chat/chat_window.py b/MAVProxy/modules/mavproxy_chat/chat_window.py index d75b5b156d..7e2ec67385 100644 --- a/MAVProxy/modules/mavproxy_chat/chat_window.py +++ b/MAVProxy/modules/mavproxy_chat/chat_window.py @@ -60,7 +60,6 @@ def __init__(self, mpstate, wait_for_command_ack_fn): self.record_button = wx.Button(self.frame, id=-1, label="Rec", size=(75, 25)) self.record_button.Bind(wx.EVT_LEFT_DOWN, self.record_button_pushed) self.record_button.Bind(wx.EVT_LEFT_UP, self.record_button_released) - self.frame.Bind(wx.EVT_BUTTON, self.record_button_click, self.record_button) self.horiz_sizer.Add(self.record_button, proportion=0, flag=wx.ALIGN_TOP | wx.ALL, border=5) # add an input text box @@ -122,14 +121,14 @@ def apikey_close_button_click(self, event): self.apikey_frame.Hide() # record button clicked - def record_button_click(self, event): + def record_button_pushed(self, event): # run record_button_click_execute in a new thread - th = Thread(target=self.record_button_click_execute, args=(event,)) + th = Thread(target=self.record_button_pushed_execute, args=(event,)) th.start() - # record button clicked - def record_button_click_execute(self, event): - # record audio + # record button pushed + def record_button_pushed_execute(self, event): + # record audio in a new thread self.set_status_text("recording audio") rec_filename = self.chat_voice_to_text.record_audio() if rec_filename is None: @@ -148,15 +147,11 @@ def record_button_click_execute(self, event): self.set_status_text("sending text to assistasnt") self.send_text_to_assistant() - # record button pushed - def record_button_pushed(self, event): - # run record_button_click_execute in a new thread - self.set_status_text("recording button pressed") - # record button released def record_button_released(self, event): - # run record_button_click_execute in a new thread + # request voice-to-text to stop recording self.set_status_text("recording button released") + self.chat_voice_to_text.stop_record_audio() # cancel button clicked def cancel_button_click(self, event):