finally google home handler fixed

new_voices
jocavdh 5 years ago
parent 81d8e9317b
commit da58fc7026

@ -8,6 +8,7 @@ import json
from time import sleep
from logic import tts, read_script
from config import characters, directions
from speaker import google, on_waiting, on_message
HOST = 'localhost'
PORT = 1883
@ -19,6 +20,8 @@ def on_connect(client, userdata, flags, rc):
client.subscribe("hermes/nlu/intentNotRecognized")
client.subscribe('hermes/intent/jocavdh:ask')
client.subscribe('hermes/intent/jocavdh:answer_yes')
client.subscribe("hermes/asr/textCaptured")
client.subscribe("hermes/dialogueManager/sessionQueued")
def on_introduce(client,data,msg, line_number = 0):
data = json.loads(msg.payload)
@ -52,24 +55,27 @@ def on_introduce(client,data,msg, line_number = 0):
break
if action == 'listen_google_home':
print('ok google')
client.publish('hermes/dialogueManager/endSession', json.dumps({
'sessionId': sessionId
}))
# 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'
# client.publish('hermes/dialogueManager/startSession', json.dumps({
# 'siteId': 'default',
# 'init': {'type': 'action', 'canBeEnqueued': True, 'sendIntentNotRecognized': True, 'intentFilter':['jocavdh:answer_yes']}
# }))
return line_number
# # client.publish("hermes/asr/toggleOn")
# # client.publish('hermes/asr/startListening', json.dumps({
# # 'siteId': 'default'
# # }))
break
# return line_number
google()
#break
def on_answer(client,data,msg):
@ -94,10 +100,11 @@ def on_answer(client,data,msg):
def onIntentNotRecognized(client, data, msg):
data = json.loads(msg.payload)
start_line = on_introduce()
print('not recognized')
line_number = 1
print('We continue on line')
print(line_number)
on_introduce(client,data,msg, start_line)
on_introduce(client,data,msg, line_number)
client = mqtt.Client()

@ -72,7 +72,7 @@ def tts(voice, input_text, speaker):
# aplay -D mono3 /tmp/output_wav.wav
call(["aplay", fpath])
call(["aplay", "-D", "sysdefault:CARD=ArrayUAC10", fpath])
else:

@ -1,2 +1,2 @@
ROGUE: [Listens to Google Home] Give me
SAINT: Do that.
ROGUE: [Listens to Google Home] Hi, I am Rogue. I kidnapped this little speaker. O K Google, please introduce yourself.
SAINT: I am Saint, and I have this dreadfully sad voice.

@ -0,0 +1,92 @@
from logic import tts, read_script
from config import characters, directions
# Fuction to RUN THE PLAY
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/dialogueManager/sessionQueued")
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,
}))
def google():
client = mqtt.Client()
client.connect(HOST, PORT, 60)
client.on_connect = on_connect
client.connected_flag=False
listening = False
switch = 5
if switch == 5:
# for character, line, direction in read_script('play_scripts/introduction.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)
switch = 5
if switch == 5:
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
sleep(1)
print('The play is over.')
# return
Loading…
Cancel
Save