another change

new_voices
jocavdh 5 years ago
parent c6b775229e
commit eb666374d6

@ -7,7 +7,6 @@ import json
from time import sleep
from logic import tts, read_script
from config import characters, directions
from speaker import listen_to_speaker, on_waiting, on_message
# === SETUP OF MQTT PART 1 ===
@ -31,9 +30,9 @@ def on_play_intro_act(client,data,msg):
data = json.loads(msg.payload)
sessionId = data['sessionId']
script_lines = read_script('play_scripts/interruption_02.txt')
script_lines = read_script('play_scripts/demo.txt') # pick a random introduction script
for character, line, direction in script_lines[line_number:]:
for character, line, direction in script_lines:
input_text = line
voice = characters.get(character)[0]
speaker = characters.get(character)[1]
@ -41,9 +40,12 @@ def on_play_intro_act(client,data,msg):
# 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 == 'start_interrogation':
# call(["python3", "play_interrogation_act.py"])
if action == 'listen_audience':
print('listen to the audience')
@ -53,13 +55,10 @@ def on_play_intro_act(client,data,msg):
client.publish('hermes/dialogueManager/startSession', json.dumps({
'siteId': 'default',
'init': {'type': 'action', 'canBeEnqueued': True, 'intentFilter':['jocavdh:answer_yes']}
'init': {'type': 'action', 'canBeEnqueued': True, 'intentFilter':['jocavdh:question_continue_act']}
}))
break
if action == 'listen_google_home':
listen_to_speaker()
# Function which is triggered when the intent question_continue_act is activated
def on_question_continue_act(client,data,msg):
@ -72,29 +71,12 @@ def on_question_continue_act(client,data,msg):
speaker = 'default'
if answer_value == 'no':
# 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()
print('no')
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)
call(["python3", "play_interrogation_act.py"])
print('The play is over.')
print('The play is over.')
# Function which is triggered when no intent is recognized
def onIntentNotRecognized(client, data, msg):

@ -15,7 +15,8 @@ characters = {"ROGUE":["dfki-prudence", "mono1"], "SAINT":["dfki-obadiah", "mono
# Dictionary to link stage directions to a particular formal action
directions = {
'Wait for audience':'listen_audience',
'Ask audience':'listen_audience',
'Start interrogation':'start_interrogation',
'Listens to Google Home':'listen_google_home',
'Music':'audio'
}

@ -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: 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.
SAINT: [Ask audience] do you want to continue?

@ -1,2 +1,3 @@
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
~/marytts/bin/marytts-server &
snips-skill-server -v &
snips-watch -v

@ -0,0 +1,3 @@
#!/bin/bash
~/marytts/bin/marytts-server
Loading…
Cancel
Save