From ae8e9e189f5440ce6dfeb4700eb4234f499400e6 Mon Sep 17 00:00:00 2001 From: m-barker Date: Mon, 29 Jan 2024 10:47:26 +0000 Subject: [PATCH] feat: tiago repeat after me demo script --- .../CMakeLists.txt | 1 + .../scripts/repeat_after_me.py | 58 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 common/speech/lasr_speech_recognition_whisper/scripts/repeat_after_me.py diff --git a/common/speech/lasr_speech_recognition_whisper/CMakeLists.txt b/common/speech/lasr_speech_recognition_whisper/CMakeLists.txt index 75240eddb..9c2fe1f57 100644 --- a/common/speech/lasr_speech_recognition_whisper/CMakeLists.txt +++ b/common/speech/lasr_speech_recognition_whisper/CMakeLists.txt @@ -170,6 +170,7 @@ catkin_install_python(PROGRAMS nodes/transcribe_microphone_server scripts/list_microphones.py scripts/test_microphones.py + scripts/repeat_after_me.py DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} ) diff --git a/common/speech/lasr_speech_recognition_whisper/scripts/repeat_after_me.py b/common/speech/lasr_speech_recognition_whisper/scripts/repeat_after_me.py new file mode 100644 index 000000000..2e6b20622 --- /dev/null +++ b/common/speech/lasr_speech_recognition_whisper/scripts/repeat_after_me.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +import rospy +import actionlib +from lasr_voice import Voice # type: ignore +from lasr_speech_recognition_msgs.srv import TranscribeAudio, TranscribeAudioResponse # type: ignore +from lasr_speech_recognition_msgs.msg import ( # type: ignore + TranscribeSpeechAction, + TranscribeSpeechGoal, +) + +# import actionlib +rospy.init_node("repeat") + +USE_ACTIONLIB = True + +voice = Voice() + + +if USE_ACTIONLIB: + client = actionlib.SimpleActionClient("transcribe_speech", TranscribeSpeechAction) + client.wait_for_server() + repeating = False + rospy.loginfo("Done waiting") + while not rospy.is_shutdown(): + goal = TranscribeSpeechGoal() + client.send_goal(goal) + client.wait_for_result() + result = client.get_result() + text = result.sequence + print(text) + if "tiago" in text.lower().strip(): + if "repeat" in text.lower().strip(): + repeating = True + voice.sync_tts("Okay, I'll start repeating now.") + continue + elif "stop" in text.lower().strip(): + repeating = False + voice.sync_tts("Okay, I'll stop repeating now.") + break + if repeating: + voice.sync_tts(f"I heard {text}") +else: + transcribe = rospy.ServiceProxy("/whisper/transcribe_audio", TranscribeAudio) + repeating = False + while not rospy.is_shutdown(): + text = transcribe().phrase + print(text) + if "tiago" in text.lower().strip(): + if "repeat" in text.lower().strip(): + repeating = True + voice.sync_tts("Okay, I'll start repeating now.") + continue + elif "stop" in text.lower().strip(): + repeating = False + voice.sync_tts("Okay, I'll stop repeating now.") + break + if repeating: + voice.sync_tts(f"I heard {text}")