Skip to content

Commit

Permalink
chat: use queue to send stop-recording-cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
rmackay9 committed Aug 6, 2024
1 parent e2c995a commit 3ba5cff
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions MAVProxy/modules/mavproxy_chat/chat_voice_to_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
print("chat: failed to import pyaudio, wave or openai. See https://ardupilot.org/mavproxy/docs/modules/chat.html")
exit()

from MAVProxy.modules.lib import multiproc

class chat_voice_to_text():
def __init__(self):
# initialise variables
self.client = None
self.assistant = None
self.stop_recording = False
self.external_cmd_queue = multiproc.Queue()

# set the OpenAI API key
def set_api_key(self, api_key_str):
Expand Down Expand Up @@ -66,6 +68,10 @@ def record_audio(self):
data = stream.read(1024)
frames.append(data)
curr_time = time.time()
queue_item = self.external_cmd_queue.get_nowait()
if queue_item == "stop":
print("chat: voice-to-text got stop command!")
break

# Stop and close the stream
stream.stop_stream()
Expand All @@ -85,6 +91,7 @@ def record_audio(self):
def stop_record_audio(self):
print("chat: voice-to-text will stop recording!")
self.stop_recording = True
self.external_cmd_queue.put("stop")

# convert audio to text
# returns transcribed text on success or None if failed
Expand Down

0 comments on commit 3ba5cff

Please sign in to comment.