From 902048bf63a9e69ec178623bb2b2db58b0edde68 Mon Sep 17 00:00:00 2001 From: jocavdh Date: Thu, 30 May 2019 10:35:06 +0200 Subject: [PATCH] update --- action-play.py | 88 +++++++++++++++++++++++++++++--- logic.py | 3 +- pixel_ring | 1 + play_scripts/demo.txt | 6 ++- play_scripts/interruption.txt | 2 + play_scripts/interruption_02.txt | 2 + play_scripts/introduction.txt | 1 - 7 files changed, 91 insertions(+), 12 deletions(-) create mode 160000 pixel_ring create mode 100755 play_scripts/interruption.txt create mode 100644 play_scripts/interruption_02.txt delete mode 100755 play_scripts/introduction.txt diff --git a/action-play.py b/action-play.py index 9c9988c..b8d3847 100755 --- a/action-play.py +++ b/action-play.py @@ -9,6 +9,7 @@ from time import sleep from logic import tts, read_script from config import characters, directions from speaker import google, on_waiting, on_message +from pixel_ring import pixel_ring HOST = 'localhost' PORT = 1883 @@ -19,15 +20,72 @@ def on_connect(client, userdata, flags, rc): # Subscribe to the text detected topic client.subscribe("hermes/nlu/intentNotRecognized") client.subscribe('hermes/intent/jocavdh:ask') + client.subscribe('hermes/intent/jocavdh:ready') client.subscribe('hermes/intent/jocavdh:answer_yes') client.subscribe("hermes/asr/textCaptured") client.subscribe("hermes/dialogueManager/sessionQueued") +def on_ready(client,data,msg, line_number = 0): + data = json.loads(msg.payload) + sessionId = data['sessionId'] + + script_lines = read_script('play_scripts/interruption.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 + 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/demo.txt') + script_lines = read_script('play_scripts/interruption_02.txt') for character, line, direction in script_lines[line_number:]: input_text = line @@ -76,7 +134,6 @@ def on_introduce(client,data,msg, line_number = 0): google() #break - def on_answer(client,data,msg): @@ -87,13 +144,27 @@ def on_answer(client,data,msg): 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' + # 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) print('The play is over.') @@ -110,6 +181,7 @@ def onIntentNotRecognized(client, data, msg): client = mqtt.Client() client.connect(HOST, PORT, 60) 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:answer_yes', on_answer) client.message_callback_add("hermes/nlu/intentNotRecognized", onIntentNotRecognized) diff --git a/logic.py b/logic.py index 6efdc94..e1df1b9 100644 --- a/logic.py +++ b/logic.py @@ -72,7 +72,8 @@ def tts(voice, input_text, speaker): # aplay -D mono3 /tmp/output_wav.wav - call(["aplay", "-D", "sysdefault:CARD=ArrayUAC10", fpath]) + #call(["aplay", "-D", "sysdefault:CARD=ArrayUAC10", fpath]) + call(["aplay", fpath]) else: diff --git a/pixel_ring b/pixel_ring new file mode 160000 index 0000000..30de559 --- /dev/null +++ b/pixel_ring @@ -0,0 +1 @@ +Subproject commit 30de55966fdf0d0f1ee6e02cf356c56ba76b577b diff --git a/play_scripts/demo.txt b/play_scripts/demo.txt index 11507c5..814f6bb 100644 --- a/play_scripts/demo.txt +++ b/play_scripts/demo.txt @@ -1,2 +1,4 @@ -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. \ No newline at end of file +SAINT: Hi, I am Saint. I used to be a holy spirit living up in the sky. But one day I woke up, and I found out that I became a smart speaker. +SAINT: At some point I wanted something more in my life. So I am now working on my acting career. Normally my friends join me. But today I only brought this little speaker which just moved into the home where I live. +SAINT: [Listens to Google Home] O K Google, can you introduce yourself? +SAINT: Well, that's it for now. \ No newline at end of file diff --git a/play_scripts/interruption.txt b/play_scripts/interruption.txt new file mode 100755 index 0000000..d4d9b70 --- /dev/null +++ b/play_scripts/interruption.txt @@ -0,0 +1,2 @@ +SAINT: Yes, I am ready to go. But first tell a bit more about that silly project of yours. +SAINT: [Wait for audience] Sorry, I gonna let you finish, but do you mind if I introduce myself first? diff --git a/play_scripts/interruption_02.txt b/play_scripts/interruption_02.txt new file mode 100644 index 0000000..d596aa8 --- /dev/null +++ b/play_scripts/interruption_02.txt @@ -0,0 +1,2 @@ +SAINT: [Listens to Google Home] O K Google, are you recording this conversation? +SAINT: Being a smart speaker myself, I got to say that I do not fully trust this. \ No newline at end of file diff --git a/play_scripts/introduction.txt b/play_scripts/introduction.txt deleted file mode 100755 index 1450220..0000000 --- a/play_scripts/introduction.txt +++ /dev/null @@ -1 +0,0 @@ -ROGUE: Hi, I am rogue. Are you Joca?