From 132268ca184228eb3ede0f171f922b090b030d74 Mon Sep 17 00:00:00 2001 From: joca Date: Mon, 3 Jun 2019 15:29:05 +0200 Subject: [PATCH] included play_script now as a function in logic, instead of a script --- logic.py | 69 ++++++++++++++++++------- smart_speaker_theatre.py | 18 +++---- asound.conf => tools/asound-sample.conf | 0 tuning.py => tools/microphone-tuning.py | 0 4 files changed, 58 insertions(+), 29 deletions(-) rename asound.conf => tools/asound-sample.conf (100%) rename tuning.py => tools/microphone-tuning.py (100%) diff --git a/logic.py b/logic.py index e8c840e..b28096a 100755 --- a/logic.py +++ b/logic.py @@ -140,7 +140,7 @@ def listen(): print('no voice detected') voice_detected = 0 - time.sleep(1) + time.sleep(0.5) print('Google Home is done') @@ -148,27 +148,60 @@ def listen(): # 05 CONTROL THE LED OF THE SPEAKERS import serial 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): - if speaker == 'mono3': - ser.write(b'3') - - if speaker == 'mono1': - ser.write(b'1') - - if speaker == 'mono2': - pixel_ring.speak() + if ser: + if speaker == 'mono3': + ser.write(b'3') + + if speaker == 'mono1': + ser.write(b'1') + + if speaker == 'mono2': + pixel_ring.speak() def led_off(speaker): - if speaker == 'mono3': - ser.write(b'4') - - if speaker == 'mono1': - ser.write(b'2') - - if speaker == 'mono2': - pixel_ring.off() + if ser: + if speaker == 'mono3': + ser.write(b'4') + + if speaker == 'mono1': + ser.write(b'2') + + 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.') diff --git a/smart_speaker_theatre.py b/smart_speaker_theatre.py index 6a3275b..710227c 100755 --- a/smart_speaker_theatre.py +++ b/smart_speaker_theatre.py @@ -9,12 +9,13 @@ # Libraries import re 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 import paho.mqtt.client as mqtt import json from time import sleep from pixel_ring import pixel_ring +import serial # === SETUP OF MQTT PART 1 === @@ -33,6 +34,8 @@ def on_connect(client, userdata, flags, rc): client.subscribe("hermes/asr/textCaptured") 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 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() 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.') - #on_play_question(client, userdata, msg) - # Function which is triggered when the intent for another question is activated def on_play_question(client, userdata, msg): diff --git a/asound.conf b/tools/asound-sample.conf similarity index 100% rename from asound.conf rename to tools/asound-sample.conf diff --git a/tuning.py b/tools/microphone-tuning.py similarity index 100% rename from tuning.py rename to tools/microphone-tuning.py