Compare commits

...

3 Commits

@ -140,7 +140,7 @@ def listen():
print('no voice detected') print('no voice detected')
voice_detected = 0 voice_detected = 0
time.sleep(1) time.sleep(0.5)
print('Google Home is done') print('Google Home is done')
@ -148,10 +148,11 @@ def listen():
# 05 CONTROL THE LED OF THE SPEAKERS # 05 CONTROL THE LED OF THE SPEAKERS
import serial import serial
from pixel_ring import pixel_ring from pixel_ring import pixel_ring
ser = serial.Serial('/dev/ttyACM0', 1000000) # Establish the connection on a specific port from smart_speaker_theatre import ser
def led_on(speaker): def led_on(speaker):
if ser:
if speaker == 'mono3': if speaker == 'mono3':
ser.write(b'3') ser.write(b'3')
@ -163,6 +164,7 @@ def led_on(speaker):
def led_off(speaker): def led_off(speaker):
if ser:
if speaker == 'mono3': if speaker == 'mono3':
ser.write(b'4') ser.write(b'4')
@ -172,3 +174,34 @@ def led_off(speaker):
if speaker == 'mono2': if speaker == 'mono2':
pixel_ring.off() pixel_ring.off()
# Play the theatre acts
def play_script(file):
for character, line, direction in read_script(file):
input_text = line
voice = characters.get(character)[0]
speaker = characters.get(character)[1]
action = directions.get(direction[0])
led_on(speaker)
tts(voice, input_text, speaker)
if action == 'listen_google_home':
listen()
if action == 'music':
print('play audioclip')
playing = True
while playing:
call(["aplay", "-D", speaker, "/usr/share/snips/congress.wav"])
playing = False
led_off(speaker)
sleep(0.2) # Add a short pause between the lines
print('The act is done.')

@ -1,139 +0,0 @@
#!/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, led_on, led_off, select_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
file = select_script('scripts_play/intro/')
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.')

@ -1,3 +1,3 @@
ROGUE: Test a question ROGUE: Test a question
RASA: Well, O K Google. What time is it? [Listen to Google Home] RASA: Well, O K Google. What is the weather in Rotterdam? [Listen to Google Home]
SAINT: We got an answer. SAINT: We got an answer.

@ -9,12 +9,13 @@
# Libraries # Libraries
import re import re
from config import characters, directions from config import characters, directions
from logic import tts, read_script, select_script from logic import tts, read_script, select_script, play_script
from subprocess import call from subprocess import call
import paho.mqtt.client as mqtt import paho.mqtt.client as mqtt
import json import json
from time import sleep from time import sleep
from pixel_ring import pixel_ring from pixel_ring import pixel_ring
import serial
# === SETUP OF MQTT PART 1 === # === SETUP OF MQTT PART 1 ===
@ -33,6 +34,8 @@ def on_connect(client, userdata, flags, rc):
client.subscribe("hermes/asr/textCaptured") client.subscribe("hermes/asr/textCaptured")
client.subscribe("hermes/dialogueManager/sessionQueued") client.subscribe("hermes/dialogueManager/sessionQueued")
# Set up serial connection with the microcontroller that controls the speaker LED's
ser = serial.Serial('/dev/ttyACM0', 1000000)
@ -43,19 +46,13 @@ def on_wakeword(client, userdata, msg):
# Function which is triggered when the intent introduction is activated # Function which is triggered when the intent introduction is activated
def on_play_intro(client,userdata,msg): def on_play_intro(client,userdata,msg):
# # disable this intent to avoid playing another act triggered by the Google Home
# client.publish("hermes/dialogueManager/configure", json.dumps({ import pdb; pdb.set_trace()
# 'siteId': 'default',
# 'intents': {
# 'jocavdh:play': False
# }
# }))
path = 'scripts_play/intro/' path = 'scripts_play/intro/'
call(["python3", "act.py", 'scripts_play/intro/introduction_01.txt']) #call(["python3", "act.py", 'scripts_play/intro/introduction_01.txt'])
play_script('scripts_play/intro/introduction_01.txt')
print('The act is over.') print('The act is over.')
#on_play_question(client, userdata, msg)
# Function which is triggered when the intent for another question is activated # Function which is triggered when the intent for another question is activated
def on_play_question(client, userdata, msg): def on_play_question(client, userdata, msg):

Loading…
Cancel
Save