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