implemented new method to handle conversations with audience and google home

(to do: how to handle these events in the theatre script)
new_voices
jocavdh 6 years ago
parent a01b5221b6
commit 5ae7a70a03

@ -16,12 +16,9 @@ PORT = 1883
def on_connect(client, userdata, flags, rc):
print("Connected to {0} with result code {1}".format(HOST, rc))
# Subscribe to the text detected topic
client.subscribe("hermes/asr/textCaptured")
client.subscribe("hermes/nlu/intentNotRecognized")
client.subscribe('hermes/intent/jocavdh:ask')
client.subscribe('hermes/intent/jocavdh:answer_yes')
client.subprocess('hermes/dialogueManager/sessionEnded')
client.subprocess('hermes/dialogueManager/sessionStarted')
def on_introduce(client,data,msg):
data = json.loads(msg.payload)
@ -35,16 +32,40 @@ def on_introduce(client,data,msg):
# Some way to do something with the stage directions will come here
action = directions.get(direction[0])
tts(voice, input_text, speaker)
print('say this sentence')
client.publish('hermes/dialogueManager/endSession', json.dumps({
'sessionId': sessionId
}))
if action == 'listen_audience':
print('listen to the audience')
client.publish('hermes/dialogueManager/startSession', json.dumps({
'siteId': 'default',
'init': {'type': 'action', 'canBeEnqueued': False, 'intentFilter':['jocavdh:answer_yes']}
}))
client.publish('hermes/dialogueManager/endSession', json.dumps({
'sessionId': sessionId
}))
client.publish('hermes/dialogueManager/startSession', json.dumps({
'siteId': 'default',
'init': {'type': 'action', 'canBeEnqueued': True, 'intentFilter':['jocavdh:answer_yes']}
}))
break
if action == 'listen_google_home':
print('ok google')
client.publish('hermes/dialogueManager/endSession', json.dumps({
'sessionId': sessionId
}))
client.publish('hermes/dialogueManager/startSession', json.dumps({
'siteId': 'default',
'init': {'type': 'action', 'canBeEnqueued': True, 'sendIntentNotRecognized': True}
}))
# client.publish("hermes/asr/toggleOn")
# client.publish('hermes/asr/startListening', json.dumps({
# 'siteId': 'default'
# }))
break
def on_answer(client,data,msg):
@ -52,28 +73,34 @@ def on_answer(client,data,msg):
answer_value = data['slots'][0]['value']['value']
print(answer_value)
voice = "dfki-obadiah"
speaker = 'default'
if answer_value == 'yes':
input_text = 'Lorem ipsum'
tts(voice, input_text, speaker)
#on_introduce(client,data,msg)
if answer_value == 'no':
input_text = 'nope nope nope'
tts(voice, input_text, speaker)
voice = "dfki-obadiah"
speaker = 'default'
print('The play is over.')
def onIntentNotRecognized(client, data, msg):
data = json.loads(msg.payload)
tts(voice, input_text, speaker)
print('not recognized')
print('The play is over.')
on_introduce(client,data,msg)
client = mqtt.Client()
client.connect(HOST, PORT, 60)
client.on_connect = on_connect
client.connected_flag=False
client.message_callback_add('hermes/intent/jocavdh:ask', on_introduce)
client.message_callback_add('hermes/intent/jocavdh:answer_yes', on_answer)
client.message_callback_add('hermes/intent/jocavdh:no', on_answer)
client.message_callback_add("hermes/nlu/intentNotRecognized", onIntentNotRecognized)
print('main')
listening = False
client.loop_forever()

@ -77,109 +77,3 @@ def tts(voice, input_text, speaker):
else:
raise Exception(content)
# 03 FUNCTIONS TO RUN THE PLAY ON THE SPEAKERS
import paho.mqtt.client as mqtt
import json
from time import sleep
HOST = 'localhost'
PORT = 1883
def on_connect(client, userdata, flags, rc):
print("Connected to {0} with result code {1}".format(HOST, rc))
# Subscribe to the text detected topic
client.subscribe("hermes/asr/textCaptured")
client.subscribe("hermes/nlu/intentNotRecognized")
client.subscribe('hermes/intent/jocavdh:ask')
client.subscribe('hermes/intent/jocavdh:answer_yes')
client.subprocess('hermes/dialogueManager/sessionEnded')
client.subprocess('hermes/dialogueManager/sessionStarted')
def on_message(client, userdata, msg):
print('Google Home is not speaking anymore')
client.connected_flag=True
# def on_waiting(client, userdata, msg):
# sessionId = json.loads(id.payload)
# print('delete mistaken intent')
# client.publish("hermes/dialogueManager/endSession", json.dumps({
# 'sessionId': sessionId,
# }))
client = mqtt.Client()
client.connect(HOST, PORT, 60)
client.on_connect = on_connect
client.connected_flag=False
listening = False
def play():
for character, line, direction in read_script('play_scripts/demo.txt'):
input_text = line
voice = characters.get(character)[0]
speaker = characters.get(character)[1]
#speaker = 'default'
# Some way to do something with the stage directions will come here
action = directions.get(direction[0])
tts(voice, input_text, speaker)
if action == 'listen_google_home':
print('Waiting for the Google Home to finish its talk')
# # start voice activity detection
# client.publish("hermes/asr/startListening", json.dumps({
# 'siteId': 'default',
# 'init': {
# 'type': 'action',
# 'canBeEnqueued': True
# }
# }))
client.publish("hermes/asr/startListening", json.dumps({
'siteId': 'default'
}))
# create callback
client.on_message = on_message
listening = True
while listening:
client.loop()
#client.on_message = on_message
client.message_callback_add('hermes/asr/textCaptured', on_message)
if client.connected_flag:
sleep(1)
print('Continue the play')
client.connected_flag = False
# client.message_callback_add('hermes/dialogueManager/sessionQueued', on_waiting)
break
if action == 'audio':
print('play audioclip')
playing = True
while playing:
call(["aplay", "-D", speaker, "/usr/share/snips/congress.wav"])
playing = False
if action == 'listen_audience':
print('ask the audience')
sleep(1)
print('This act is done.')
return

@ -1 +1,2 @@
ROGUE: Give me
ROGUE: [Listens to Google Home] Give me
SAINT: Do that.
Loading…
Cancel
Save