another change
parent
c6b775229e
commit
eb666374d6
@ -0,0 +1,105 @@
|
|||||||
|
#!/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
|
||||||
|
|
||||||
|
|
||||||
|
# === FUNCTIONS THAT ARE TRIGGERED WHEN AN INTENT IS DETECTED ===
|
||||||
|
|
||||||
|
# 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")
|
||||||
|
|
||||||
|
# Set Flag when Google Home is done speaking
|
||||||
|
def on_message(client, userdata, msg):
|
||||||
|
print('Google Home is not speaking anymore')
|
||||||
|
client.connected_flag=True
|
||||||
|
|
||||||
|
# Remove any detected intents that are activated by the speaking Google Home
|
||||||
|
def on_waiting(client, userdata, msg):
|
||||||
|
sessionId = json.loads(id.payload)
|
||||||
|
print('delete mistaken intent')
|
||||||
|
client.publish("hermes/dialogueManager/endSession", json.dumps({
|
||||||
|
'sessionId': sessionId,
|
||||||
|
}))
|
||||||
|
|
||||||
|
client = mqtt.Client()
|
||||||
|
client.connect(HOST, PORT, 60)
|
||||||
|
client.on_connect = on_connect
|
||||||
|
client.connected_flag=False
|
||||||
|
|
||||||
|
listening = False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for character, line, direction in read_script('play_scripts/interruption_02.txt'):
|
||||||
|
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':
|
||||||
|
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
|
||||||
|
# }
|
||||||
|
# }))
|
||||||
|
|
||||||
|
client.publish("hermes/asr/startListening", json.dumps({
|
||||||
|
'siteId': 'default'
|
||||||
|
}))
|
||||||
|
|
||||||
|
# create callback
|
||||||
|
client.on_message = on_message
|
||||||
|
listening = True
|
||||||
|
|
||||||
|
while listening:
|
||||||
|
client.loop()
|
||||||
|
|
||||||
|
#client.on_message = on_message
|
||||||
|
client.message_callback_add('hermes/asr/textCaptured', on_message)
|
||||||
|
|
||||||
|
if client.connected_flag:
|
||||||
|
sleep(1)
|
||||||
|
print('Continue the play')
|
||||||
|
client.connected_flag = False
|
||||||
|
client.message_callback_add('hermes/dialogueManager/sessionQueued', on_waiting)
|
||||||
|
break
|
||||||
|
|
||||||
|
if action == 4:
|
||||||
|
print('play audioclip')
|
||||||
|
playing = True
|
||||||
|
|
||||||
|
while playing:
|
||||||
|
call(["aplay", "-D", speaker, "/usr/share/snips/congress.wav"])
|
||||||
|
playing = False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
sleep(1)
|
||||||
|
|
||||||
|
|
||||||
|
print('The act is over.')
|
@ -1,4 +1 @@
|
|||||||
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: [Ask audience] do you want to continue?
|
||||||
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.
|
|
@ -1,2 +1,3 @@
|
|||||||
SAINT: [Listens to Google Home] O K Google, are you recording this conversation?
|
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.
|
SAINT: Being a smart speaker myself, I got to say that I do not fully trust this.
|
||||||
|
ROGUE: Test Test
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
sudo systemctl restart snips-skill-server -v &
|
||||||
|
sudo systemctl restart snips-watch -v
|
@ -1,92 +0,0 @@
|
|||||||
from logic import tts, read_script
|
|
||||||
from config import characters, directions
|
|
||||||
|
|
||||||
# Fuction to RUN THE PLAY
|
|
||||||
import paho.mqtt.client as mqtt
|
|
||||||
import json
|
|
||||||
from time import sleep
|
|
||||||
|
|
||||||
HOST = 'localhost'
|
|
||||||
PORT = 1883
|
|
||||||
|
|
||||||
|
|
||||||
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")
|
|
||||||
|
|
||||||
|
|
||||||
def on_message(client, userdata, msg):
|
|
||||||
print('Google Home is not speaking anymore')
|
|
||||||
client.connected_flag=True
|
|
||||||
|
|
||||||
def on_waiting(client, userdata, msg):
|
|
||||||
sessionId = json.loads(id.payload)
|
|
||||||
print('delete mistaken intent')
|
|
||||||
client.publish("hermes/dialogueManager/endSession", json.dumps({
|
|
||||||
'sessionId': sessionId,
|
|
||||||
}))
|
|
||||||
|
|
||||||
def listen_to_speaker():
|
|
||||||
client = mqtt.Client()
|
|
||||||
client.connect(HOST, PORT, 60)
|
|
||||||
client.on_connect = on_connect
|
|
||||||
client.connected_flag=False
|
|
||||||
|
|
||||||
listening = False
|
|
||||||
switch = 5
|
|
||||||
|
|
||||||
if switch == 5:
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# for character, line, direction in read_script('play_scripts/introduction.txt'):
|
|
||||||
# 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)
|
|
||||||
switch = 5
|
|
||||||
|
|
||||||
if switch == 5:
|
|
||||||
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
|
|
||||||
# }
|
|
||||||
# }))
|
|
||||||
|
|
||||||
client.publish("hermes/asr/startListening", json.dumps({
|
|
||||||
'siteId': 'default'
|
|
||||||
}))
|
|
||||||
|
|
||||||
# create callback
|
|
||||||
client.on_message = on_message
|
|
||||||
listening = True
|
|
||||||
|
|
||||||
while listening:
|
|
||||||
client.loop()
|
|
||||||
|
|
||||||
#client.on_message = on_message
|
|
||||||
client.message_callback_add('hermes/asr/textCaptured', on_message)
|
|
||||||
|
|
||||||
if client.connected_flag:
|
|
||||||
sleep(1)
|
|
||||||
print('Continue the play')
|
|
||||||
client.connected_flag = False
|
|
||||||
client.message_callback_add('hermes/dialogueManager/sessionQueued', on_waiting)
|
|
||||||
break
|
|
||||||
|
|
||||||
sleep(1)
|
|
||||||
|
|
||||||
|
|
||||||
print('The play is over.')
|
|
||||||
|
|
||||||
# return
|
|
@ -1,5 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
~/marytts/bin/marytts-server &
|
|
||||||
snips-skill-server -v &
|
snips-skill-server -v &
|
||||||
snips-watch -v
|
snips-watch -v
|
Loading…
Reference in New Issue