Skip to content

Commit

Permalink
chat: pass stop recording to voice-to-text
Browse files Browse the repository at this point in the history
  • Loading branch information
rmackay9 committed Aug 6, 2024
1 parent 86032e8 commit e2c995a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
2 changes: 2 additions & 0 deletions MAVProxy/modules/mavproxy_chat/chat_voice_to_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
19 changes: 7 additions & 12 deletions MAVProxy/modules/mavproxy_chat/chat_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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):
Expand Down

0 comments on commit e2c995a

Please sign in to comment.