Skip to content

Commit

Permalink
feat: tiago repeat after me demo script
Browse files Browse the repository at this point in the history
  • Loading branch information
m-barker committed Jan 29, 2024
1 parent 669506b commit ae8e9e1
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}
)

Expand Down
Original file line number Diff line number Diff line change
@@ -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}")

0 comments on commit ae8e9e1

Please sign in to comment.