simpler and cleaned up backend including handy debugging scripts
parent
eb666374d6
commit
be4a79c3e9
@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
marytts/bin/marytts-server
|
@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
sudo ./smart_speaker_theatre.py
|
@ -1,5 +1,20 @@
|
||||
# Smart speaker theatre backend
|
||||
# Script reader
|
||||
|
||||
Scripts which turn detected user intents in actions done by the speakers.
|
||||
This programme reads out a theatre script, using the speech synthesizer Mary TTS.
|
||||
|
||||
Work in progress.
|
||||
Install mary-tts following the instructions in the pdf and start it
|
||||
then run the play_script.py
|
||||
|
||||
|
||||
----
|
||||
Writing new plays
|
||||
|
||||
As an input, write a play in the following format:
|
||||
|
||||
CHARACTERNAME: [ stage directions ] text to say
|
||||
|
||||
Put the script in the plays directory, and put the filename in play_script.py.
|
||||
|
||||
Use instructions.py to set-up the characters and the voices.
|
||||
|
||||
Stage directions (for example lights, silences etc.) are still in development
|
||||
|
@ -1,104 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Libraries
|
||||
import paho.mqtt.client as mqtt
|
||||
import json
|
||||
from time import sleep
|
||||
from logic import tts, read_script
|
||||
from config import characters, directions
|
||||
|
||||
|
||||
# === 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))
|
||||
client.subscribe('hermes/intent/jocavdh:play_intro_act') # to check for intent to play the act
|
||||
client.subscribe('hermes/intent/jocavdh:question_continue_act') # to check for the intent to continue to the next act
|
||||
client.subscribe("hermes/nlu/intentNotRecognized") # to check if the speaker didn't understand the user, trigger for fallback function
|
||||
|
||||
|
||||
# === FUNCTIONS THAT ARE TRIGGERED WHEN AN INTENT IS DETECTED ===
|
||||
|
||||
# Function which is triggered when the intent play_intro_act is activated
|
||||
def on_play_intro_act(client,data,msg):
|
||||
data = json.loads(msg.payload)
|
||||
sessionId = data['sessionId']
|
||||
|
||||
script_lines = read_script('play_scripts/demo.txt') # pick a random introduction script
|
||||
|
||||
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)
|
||||
print('say this sentence')
|
||||
|
||||
# if action == 'start_interrogation':
|
||||
# call(["python3", "play_interrogation_act.py"])
|
||||
|
||||
|
||||
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:question_continue_act']}
|
||||
}))
|
||||
|
||||
break
|
||||
|
||||
# Function which is triggered when the intent question_continue_act is activated
|
||||
def on_question_continue_act(client,data,msg):
|
||||
|
||||
data = json.loads(msg.payload)
|
||||
answer_value = data['slots'][0]['value']['value']
|
||||
print(answer_value)
|
||||
|
||||
voice = "dfki-obadiah"
|
||||
speaker = 'default'
|
||||
|
||||
if answer_value == 'no':
|
||||
print('no')
|
||||
|
||||
if answer_value == 'yes':
|
||||
call(["python3", "play_interrogation_act.py"])
|
||||
|
||||
print('The play is over.')
|
||||
|
||||
# Function which is triggered when no intent is recognized
|
||||
def onIntentNotRecognized(client, data, msg):
|
||||
data = json.loads(msg.payload)
|
||||
line_number = 1
|
||||
print('We continue on line')
|
||||
print(line_number)
|
||||
|
||||
on_introduce(client,data,msg, line_number)
|
||||
|
||||
|
||||
# === SETUP OF MQTT PART 2 ===
|
||||
|
||||
# Initialise MQTT client
|
||||
client = mqtt.Client()
|
||||
client.connect(HOST, PORT, 60)
|
||||
client.on_connect = on_connect
|
||||
|
||||
# Connect each MQTT topic to which you subscribed to a handler function
|
||||
client.message_callback_add('hermes/intent/jocavdh:play_intro_act', on_play_intro_act)
|
||||
client.message_callback_add('hermes/intent/jocavdh:question_continue_act', on_question_continue_act)
|
||||
client.message_callback_add("hermes/nlu/intentNotRecognized", onIntentNotRecognized)
|
||||
|
||||
# Keep checking for new MQTT messages
|
||||
client.loop_forever()
|
@ -1,22 +1,14 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# play_config.py
|
||||
# config.py
|
||||
# This script contains the basic configuration of the play
|
||||
# A list of the characters and their voices
|
||||
# A list of stage directions which connect to formal instructions for the hardware
|
||||
# ---
|
||||
|
||||
# Define sound output device here
|
||||
# sound_output_device = sc.get_speaker('Scarlett')
|
||||
|
||||
# Dictionary to link characters to the right voice
|
||||
characters = {"ROGUE":["dfki-prudence", "mono1"], "SAINT":["dfki-obadiah", "mono2"], "RASA":["dfki-poppy-hsmm", "mono3"] }
|
||||
characters = {"ROGUE":["cmu-slt-hsmm", "mono2"], "SAINT":["dfki-obadiah-hsmm", "mono3"], "RASA":["dfki-poppy-hsmm", "mono1"] }
|
||||
|
||||
# Dictionary to link stage directions to a particular formal action
|
||||
directions = {
|
||||
'Ask audience':'listen_audience',
|
||||
'Start interrogation':'start_interrogation',
|
||||
'Listens to Google Home':'listen_google_home',
|
||||
'Music':'audio'
|
||||
}
|
||||
directions = {"Listen to Google Home":'listen_google_home','Music':'music'}
|
||||
|
@ -1 +1,3 @@
|
||||
SAINT: [Ask audience] do you want to continue?
|
||||
ROGUE: Do you want to continue?
|
||||
RASA: Well, I definitely want to
|
||||
SAINT: So do I
|
||||
|
@ -1,2 +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?
|
||||
SAINT: Sorry, I gonna let you finish, but do you mind if I introduce myself first?
|
||||
|
@ -1,3 +0,0 @@
|
||||
# Needed for Snips platform 1.1.0 (0.61.1)
|
||||
hermes-python>=0.3.3
|
||||
toml
|
@ -1,4 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
sudo systemctl restart snips-skill-server -v &
|
||||
sudo systemctl restart snips-watch -v
|
@ -1,34 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# Copy config.ini.default if it exists and config.ini doesn't exist.
|
||||
if [ -e config.ini.default ] && [ ! -e config.ini ]; then
|
||||
cp config.ini.default config.ini
|
||||
chmod a+w config.ini
|
||||
fi
|
||||
|
||||
PYTHON=$(command -v python3)
|
||||
VENV=venv
|
||||
|
||||
if [ -f "$PYTHON" ]; then
|
||||
|
||||
if [ ! -d $VENV ]; then
|
||||
# Create a virtual environment if it doesn't exist.
|
||||
$PYTHON -m venv $VENV
|
||||
else
|
||||
if [ -e $VENV/bin/python2 ]; then
|
||||
# If a Python2 environment exists, delete it first
|
||||
# before creating a new Python 3 virtual environment.
|
||||
rm -r $VENV
|
||||
$PYTHON -m venv $VENV
|
||||
fi
|
||||
fi
|
||||
|
||||
# Activate the virtual environment and install requirements.
|
||||
# shellcheck disable=SC1090
|
||||
. $VENV/bin/activate
|
||||
pip3 install -r requirements.txt
|
||||
|
||||
else
|
||||
>&2 echo "Cannot find Python 3. Please install it."
|
||||
fi
|
@ -0,0 +1,83 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SMART SPEAKER THEATRE
|
||||
# This script reads the triggers for activated user intents sent by Snips over MQTT
|
||||
# Using this triggers, it will start particular actions and scripts
|
||||
|
||||
|
||||
# Libraries
|
||||
import re
|
||||
from config import characters, directions
|
||||
from logic import tts, read_script
|
||||
from subprocess import call
|
||||
import paho.mqtt.client as mqtt
|
||||
import json
|
||||
from time import sleep
|
||||
from pixel_ring import pixel_ring
|
||||
|
||||
|
||||
# === 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))
|
||||
client.subscribe('hermes/intent/jocavdh:play_intro_act') # to check for intent to play the act
|
||||
client.subscribe('hermes/intent/jocavdh:question_continue_act') # to check for the intent to continue to the next act
|
||||
client.subscribe('hermes/hotword/default/detected')
|
||||
|
||||
|
||||
|
||||
|
||||
# === FUNCTIONS THAT ARE TRIGGERED WHEN AN INTENT IS DETECTED ===
|
||||
|
||||
def on_wakeword(client, userdata, msg):
|
||||
pixel_ring.think()
|
||||
|
||||
# Function which is triggered when the intent play_intro_act is activated
|
||||
def on_play_act(client, userdata, msg):
|
||||
|
||||
|
||||
# # disable this intent to avoid playing another act triggered by the Google Home
|
||||
# client.publish("hermes/dialogueManager/configure", json.dumps({
|
||||
# 'siteId': 'default',
|
||||
# 'intents': {
|
||||
# 'jocavdh:play': False
|
||||
# }
|
||||
# }))
|
||||
|
||||
call(["python3", "act.py", "play_scripts/demo.txt"])
|
||||
|
||||
# Function which is triggered when the intent introduction is activated
|
||||
def on_play_introduction(client,data,msg):
|
||||
|
||||
for character, line, direction in read_script('plays/introduction.txt'):
|
||||
input_text = line
|
||||
voice = characters.get(character)[0]
|
||||
speaker = characters.get(character)[1]
|
||||
action = directions.get(direction[0])
|
||||
tts(voice, input_text, speaker)
|
||||
sleep(1) # add a pause between each line
|
||||
|
||||
|
||||
print('The act is over.')
|
||||
|
||||
|
||||
|
||||
# === SETUP OF MQTT PART 2 ===
|
||||
|
||||
# Initialise MQTT client
|
||||
client = mqtt.Client()
|
||||
client.connect(HOST, PORT, 60)
|
||||
client.on_connect = on_connect
|
||||
|
||||
# Connect each MQTT topic to which you subscribed to a handler function
|
||||
client.message_callback_add('hermes/intent/jocavdh:play_intro_act', on_play_act)
|
||||
client.message_callback_add('hermes/hotword/default/detected', on_wakeword)
|
||||
|
||||
# Keep checking for new MQTT messages
|
||||
client.loop_forever()
|
Binary file not shown.
Loading…
Reference in New Issue