included play_script now as a function in logic, instead of a script

master
joca 5 years ago
parent defd37b303
commit 132268ca18

@ -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,27 +148,60 @@ 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 speaker == 'mono3': if ser:
ser.write(b'3') if speaker == 'mono3':
ser.write(b'3')
if speaker == 'mono1':
ser.write(b'1') if speaker == 'mono1':
ser.write(b'1')
if speaker == 'mono2':
pixel_ring.speak() if speaker == 'mono2':
pixel_ring.speak()
def led_off(speaker): def led_off(speaker):
if speaker == 'mono3': if ser:
ser.write(b'4') if speaker == 'mono3':
ser.write(b'4')
if speaker == 'mono1':
ser.write(b'2') if speaker == 'mono1':
ser.write(b'2')
if speaker == 'mono2':
pixel_ring.off() if speaker == 'mono2':
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.')

@ -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,20 +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({
# 'siteId': 'default',
# 'intents': {
# 'jocavdh:play': False
# }
# }))
import pdb; pdb.set_trace() import pdb; pdb.set_trace()
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