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 re
|
||||||
import num2words
|
import num2words
|
||||||
|
|
||||||
|
trigger_strings = ["hey glados", "hey glass", "hey glad us", "hey glades", "hey glads", "hey glad"]
|
||||||
def replace_numbers(text):
|
def replace_numbers(text):
|
||||||
return re.sub(r"(\d+)", lambda x: num2words.num2words(int(x.group(0))), text)
|
return re.sub(r"(\d+)", lambda x: num2words.num2words(int(x.group(0))), text)
|
||||||
|
|
||||||
def callback(msg):
|
def callback(msg):
|
||||||
global chat_service, pub
|
global chat_service, pub
|
||||||
resp = chat_service(msg.data, 1.0)
|
|
||||||
|
|
||||||
text = resp.text.replace('\n', ' ') # Remove line-breaks
|
for s in trigger_strings:
|
||||||
text = re.sub(r"\((.*?)\)", " ", text) # Remove anything in brackets
|
if s in msg.data.lower():
|
||||||
text = replace_numbers(text) # Make digits into text
|
text = msg.data.lower()
|
||||||
text = re.sub(' +', ' ', text) # Unnecessary white space
|
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():
|
def main():
|
||||||
global chat_service, pub
|
global chat_service, pub
|
||||||
|
|||||||
@ -86,10 +86,10 @@ def main() -> None:
|
|||||||
while not rospy.is_shutdown():
|
while not rospy.is_shutdown():
|
||||||
if TTS != None:
|
if TTS != None:
|
||||||
text_list = [TTS]
|
text_list = [TTS]
|
||||||
|
|
||||||
if len(TTS) >= 400:
|
if len(TTS) >= 400:
|
||||||
text_list = TTS.split(".")
|
text_list = TTS.split(".")
|
||||||
|
|
||||||
for t in text_list:
|
for t in text_list:
|
||||||
text = t.rstrip().lstrip()
|
text = t.rstrip().lstrip()
|
||||||
if len(text) < 1:
|
if len(text) < 1:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user