@ -9,6 +9,7 @@ from time import sleep
from logic import tts , read_script
from logic import tts , read_script
from config import characters , directions
from config import characters , directions
from speaker import google , on_waiting , on_message
from speaker import google , on_waiting , on_message
from pixel_ring import pixel_ring
HOST = ' localhost '
HOST = ' localhost '
PORT = 1883
PORT = 1883
@ -19,15 +20,16 @@ def on_connect(client, userdata, flags, rc):
# Subscribe to the text detected topic
# Subscribe to the text detected topic
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:ready ' )
client . subscribe ( ' hermes/intent/jocavdh:answer_yes ' )
client . subscribe ( ' hermes/intent/jocavdh:answer_yes ' )
client . subscribe ( " hermes/asr/textCaptured " )
client . subscribe ( " hermes/asr/textCaptured " )
client . subscribe ( " hermes/dialogueManager/sessionQueued " )
client . subscribe ( " hermes/dialogueManager/sessionQueued " )
def on_ int roduc e( client , data , msg , line_number = 0 ) :
def on_ ready ( client , data , msg , line_number = 0 ) :
data = json . loads ( msg . payload )
data = json . loads ( msg . payload )
sessionId = data [ ' sessionId ' ]
sessionId = data [ ' sessionId ' ]
script_lines = read_script ( ' play_scripts/ demo .txt' )
script_lines = read_script ( ' play_scripts/ interruption .txt' )
for character , line , direction in script_lines [ line_number : ] :
for character , line , direction in script_lines [ line_number : ] :
input_text = line
input_text = line
@ -76,7 +78,62 @@ def on_introduce(client,data,msg, line_number = 0):
google ( )
google ( )
#break
#break
sleep ( 5 )
def on_introduce ( client , data , msg , line_number = 0 ) :
data = json . loads ( msg . payload )
sessionId = data [ ' sessionId ' ]
script_lines = read_script ( ' play_scripts/interruption_02.txt ' )
for character , line , direction in script_lines [ line_number : ] :
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 )
line_number + = 1
print ( ' say this sentence ' )
if action == ' listen_audience ' :
print ( ' listen to the audience ' )
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, 'intentFilter':['jocavdh:answer_yes']}
# }))
# # client.publish("hermes/asr/toggleOn")
# # client.publish('hermes/asr/startListening', json.dumps({
# # 'siteId': 'default'
# # }))
# return line_number
google ( )
#break
def on_answer ( client , data , msg ) :
def on_answer ( client , data , msg ) :
@ -87,13 +144,27 @@ def on_answer(client,data,msg):
voice = " dfki-obadiah "
voice = " dfki-obadiah "
speaker = ' default '
speaker = ' default '
if answer_value == ' yes ' :
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 = 'Lorem ipsum'
# tts(voice, input_text, speaker)
# #on_introduce(client,data,msg)
script_lines = read_script ( ' play_scripts/demo.txt ' )
for character , line , direction in script_lines :
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 ' :
google ( )
if answer_value == ' yes ' :
input_text = ' Ok, never mind. Then I just have a little chat with this speaker over here. O K Google, tell me about your privacy policy. '
tts ( voice , input_text , speaker )
tts ( voice , input_text , speaker )
print ( ' The play is over. ' )
print ( ' The play is over. ' )
@ -110,6 +181,7 @@ def onIntentNotRecognized(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 . message_callback_add ( ' hermes/intent/jocavdh:ready ' , on_ready )
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/nlu/intentNotRecognized " , onIntentNotRecognized )
client . message_callback_add ( " hermes/nlu/intentNotRecognized " , onIntentNotRecognized )