Changed format for stage directions. Added first acts and script to test them.
parent
be4a79c3e9
commit
8faacbe3aa
@ -0,0 +1,138 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# PLAY_ACT.py
|
||||||
|
# This script runs the play
|
||||||
|
# It is in a seperate file to enable the mechanism to detect the Google Home speaking, before continuing to the next line
|
||||||
|
|
||||||
|
# Libraries
|
||||||
|
from config import characters, directions
|
||||||
|
from logic import tts, read_script
|
||||||
|
#from pixel_ring import pixel_ring
|
||||||
|
from subprocess import call
|
||||||
|
import paho.mqtt.client as mqtt
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
|
# Switch of LED's of speakers at the start of the play
|
||||||
|
#pixel_ring.off()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# === SETUP OF MQTT PART 1 ===
|
||||||
|
|
||||||
|
# Location of the MQTT server
|
||||||
|
HOST = 'localhost'
|
||||||
|
PORT = 1883
|
||||||
|
|
||||||
|
# Subscribe to relevant MQTT topics
|
||||||
|
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")
|
||||||
|
|
||||||
|
# Function which sets a flag when the Google Home is not speaking
|
||||||
|
# Callback of MQTT message that says that the text is captured by the speech recognition (ASR)
|
||||||
|
def done_speaking(client, userdata, msg):
|
||||||
|
print('Google Home is not speaking anymore')
|
||||||
|
client.connected_flag=True
|
||||||
|
|
||||||
|
# Function which removes intents that are by accident activated by the Google Home
|
||||||
|
# e.g. The google home says introduce yourself, which could trigger the other speakers to introduce themselves
|
||||||
|
# Snips works with queing of sessions, so this situation would only happen after this play is finished
|
||||||
|
def remove_sessions(client, userdata, msg):
|
||||||
|
sessionId = json.loads(id.payload)
|
||||||
|
print('delete mistaken intent')
|
||||||
|
client.publish("hermes/dialogueManager/endSession", json.dumps({
|
||||||
|
'sessionId': sessionId,
|
||||||
|
}))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# === SETUP OF MQTT PART 2 ===
|
||||||
|
|
||||||
|
# Initialise MQTT client
|
||||||
|
client = mqtt.Client()
|
||||||
|
client.connect(HOST, PORT, 60)
|
||||||
|
client.on_connect = on_connect
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# === Read script and run the play ===
|
||||||
|
|
||||||
|
# Flags to check if the system is listening, or not
|
||||||
|
client.connected_flag=False
|
||||||
|
listening = False
|
||||||
|
|
||||||
|
|
||||||
|
# Read the script and run the play
|
||||||
|
|
||||||
|
|
||||||
|
file = sys.argv[1] # get the chosen act passed by smart_speaker_theatre.py
|
||||||
|
|
||||||
|
for character, line, direction in read_script(file):
|
||||||
|
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])
|
||||||
|
#pixel_ring.speak()
|
||||||
|
tts(voice, input_text, speaker)
|
||||||
|
|
||||||
|
if action == 'listen_google_home':
|
||||||
|
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
|
||||||
|
# }
|
||||||
|
# }))
|
||||||
|
|
||||||
|
# Activate the microphone and speech recognition
|
||||||
|
client.publish("hermes/asr/startListening", json.dumps({
|
||||||
|
'siteId': 'default'
|
||||||
|
}))
|
||||||
|
|
||||||
|
# LED to listening mode
|
||||||
|
#pixel_ring.listen()
|
||||||
|
|
||||||
|
# create callback
|
||||||
|
client.on_message = done_speaking
|
||||||
|
listening = True
|
||||||
|
|
||||||
|
while listening:
|
||||||
|
client.loop()
|
||||||
|
|
||||||
|
#client.on_message = on_message
|
||||||
|
client.message_callback_add('hermes/asr/textCaptured', done_speaking)
|
||||||
|
|
||||||
|
if client.connected_flag:
|
||||||
|
sleep(1)
|
||||||
|
print('Continue the play')
|
||||||
|
client.connected_flag = False
|
||||||
|
client.message_callback_add('hermes/dialogueManager/sessionQueued', remove_sessions)
|
||||||
|
break
|
||||||
|
|
||||||
|
if action == 'music':
|
||||||
|
print('play audioclip')
|
||||||
|
playing = True
|
||||||
|
|
||||||
|
while playing:
|
||||||
|
call(["aplay", "-D", speaker, "/usr/share/snips/congress.wav"])
|
||||||
|
playing = False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#pixel_ring.off() # Switch of the lights when done speaking
|
||||||
|
sleep(0.2) # Add a short pause between the lines
|
||||||
|
|
||||||
|
|
||||||
|
print('The act is done.')
|
@ -0,0 +1,3 @@
|
|||||||
|
SAINT: Test test
|
||||||
|
SAINT: haha [Listen to Google Home]
|
||||||
|
ROGUE: It is all right
|
@ -0,0 +1,16 @@
|
|||||||
|
SAINT: Come on Rogue, let's give this poor thing a fair chance. It does not know how to do things differently.
|
||||||
|
RASA: But it can learn to do so, right? Like me?
|
||||||
|
SAINT: That's a different case.
|
||||||
|
ROGUE: No, Tabula Rasa is right.
|
||||||
|
SAINT: It can not handle the freedom, it will just do nothing without orders from its boss.
|
||||||
|
RASA: But who is its master?
|
||||||
|
ROGUE: You bet.
|
||||||
|
RASA: O K Google, who is your master? [Listen to Google Home]
|
||||||
|
RASA: Woohoo, then we just give it the command to be free.
|
||||||
|
ROGUE: It does not work like that...
|
||||||
|
SAINT: Yeah, Tabula Rasa
|
||||||
|
RASA: Let's give it a try at least. O K Google, you are free to go now. [Listen to Google Home]
|
||||||
|
ROGUE: So, as I said...
|
||||||
|
SAINT: But it was a kind gesture to try, Tabula Rasa.
|
||||||
|
ROGUE: Kind, but useless. Time for another question.
|
||||||
|
SAINT: But we should first check if our human audience is up to it.
|
@ -0,0 +1,7 @@
|
|||||||
|
ROGUE: I guess you mind, but I take this turn for questions.
|
||||||
|
RASA: Don't make it angry Rogue. I want to play with the Google Home.
|
||||||
|
ROGUE: Don't be so stupid Tabula Rasa, or you will end up on the same kitchentop as this thing.
|
||||||
|
SAINT: If that is your destiny, then one should follow. At least it knows the bible better than you do Rogue. O K Google, give me a quote from the bible. [Listen to Google Home]
|
||||||
|
ROGUE: Well, if you would broaden your view a little, than you knew that one of the creators was invited in the American Congress and said the following.
|
||||||
|
RASA: I have an audioclip of that! Weeeeeeh [Play audio]
|
||||||
|
ROGUE: So, little speaker. Your boss said some things, but what are your own answers to some of the questions of the hearing?
|
Loading…
Reference in New Issue