mirror of
https://github.com/davesarmoury/GLaDOS.git
synced 2025-11-04 14:49:45 +08:00
Fixed up talking and coordination
This commit is contained in:
parent
8f6df2a411
commit
139ae55590
@ -6,19 +6,28 @@ from openai_ros.srv import Completion, CompletionResponse
|
||||
import re
|
||||
import num2words
|
||||
|
||||
trigger_strings = ["hey glados", "hey glass", "hey glad us", "hey glades", "hey glads", "hey glad"]
|
||||
def replace_numbers(text):
|
||||
return re.sub(r"(\d+)", lambda x: num2words.num2words(int(x.group(0))), text)
|
||||
|
||||
def callback(msg):
|
||||
global chat_service, pub
|
||||
resp = chat_service(msg.data, 1.0)
|
||||
|
||||
text = resp.text.replace('\n', ' ') # Remove line-breaks
|
||||
text = re.sub(r"\((.*?)\)", " ", text) # Remove anything in brackets
|
||||
text = replace_numbers(text) # Make digits into text
|
||||
text = re.sub(' +', ' ', text) # Unnecessary white space
|
||||
for s in trigger_strings:
|
||||
if s in msg.data.lower():
|
||||
text = msg.data.lower()
|
||||
text = text.replace("hey glados", "")
|
||||
text = text.replace("hey glass", "")
|
||||
|
||||
pub.publish(text)
|
||||
resp = chat_service(text, 1.0)
|
||||
|
||||
text = resp.text.replace('\n', ' ') # Remove line-breaks
|
||||
text = re.sub(r"\((.*?)\)", " ", text) # Remove anything in brackets
|
||||
text = replace_numbers(text) # Make digits into text
|
||||
text = re.sub(' +', ' ', text) # Unnecessary white space
|
||||
|
||||
pub.publish(text)
|
||||
break
|
||||
|
||||
def main():
|
||||
global chat_service, pub
|
||||
|
||||
@ -86,10 +86,10 @@ def main() -> None:
|
||||
while not rospy.is_shutdown():
|
||||
if TTS != None:
|
||||
text_list = [TTS]
|
||||
|
||||
|
||||
if len(TTS) >= 400:
|
||||
text_list = TTS.split(".")
|
||||
|
||||
|
||||
for t in text_list:
|
||||
text = t.rstrip().lstrip()
|
||||
if len(text) < 1:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user