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