From 20d7d2c9743e726b5234f13d0e1f7fe63fc3b923 Mon Sep 17 00:00:00 2001 From: jocavdh Date: Mon, 3 Jun 2019 13:08:32 +0200 Subject: [PATCH] fix for led --- act.py | 87 ++++++++++++++++++---------------------------------- act_debug.py | 81 ------------------------------------------------ logic.py | 9 +++--- 3 files changed, 35 insertions(+), 142 deletions(-) delete mode 100644 act_debug.py diff --git a/act.py b/act.py index 4dc1db2..d7b2ef3 100644 --- a/act.py +++ b/act.py @@ -3,12 +3,11 @@ # PLAY_ACT.py # This script runs the play -# It is in a seperate file to enable the mechanism to detect the Google Home speaking, before continuing to the next line + # Libraries from config import characters, directions -from logic import tts, read_script, led_on, led_off, select_script, listen -from pixel_ring import pixel_ring +from logic import tts, read_script,listen from subprocess import call import paho.mqtt.client as mqtt import json @@ -18,75 +17,50 @@ from time import sleep # Switch of LED's of speakers at the start of the play #pixel_ring.off() +import serial +from pixel_ring import pixel_ring +ser = serial.Serial('/dev/ttyACM0', 1000000) # Establish the connection on a specific port +def led_on(speaker): -# === 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)) - # Subscribe to the text detected topic - client.subscribe("hermes/asr/textCaptured") - client.subscribe("hermes/dialogueManager/sessionQueued") - -# Function which sets a flag when the Google Home is not speaking -# Callback of MQTT message that says that the text is captured by the speech recognition (ASR) -def done_speaking(client, userdata, msg): - print('Google Home is not speaking anymore') - client.connected_flag=True - -# Function which removes intents that are by accident activated by the Google Home -# e.g. The google home says introduce yourself, which could trigger the other speakers to introduce themselves -# Snips works with queing of sessions, so this situation would only happen after this play is finished -def remove_sessions(client, userdata, msg): - sessionId = json.loads(id.payload) - print('delete mistaken intent') - client.publish("hermes/dialogueManager/endSession", json.dumps({ - 'sessionId': sessionId, - })) - - - - -# === SETUP OF MQTT PART 2 === - -# Initialise MQTT client -client = mqtt.Client() -client.connect(HOST, PORT, 60) -client.on_connect = on_connect - - + if speaker == 'mono3': + ser.write(b'3') + + if speaker == 'mono1': + ser.write(b'1') + + if speaker == 'mono2': + pixel_ring.speak() +def led_off(speaker): -# === Read script and run the play === + if speaker == 'mono3': + ser.write(b'4') + + if speaker == 'mono1': + ser.write(b'2') + + if speaker == 'mono2': + pixel_ring.off() -# Flags to check if the system is listening, or not -client.connected_flag=False -listening = False # Read the script and run the play -#file = sys.argv[1] # get the chosen act passed by smart_speaker_theatre.py -file = select_script('scripts_play/intro/') +file = sys.argv[1] # get the chosen act passed by smart_speaker_theatre.py -for character, line, direction in read_script('scripts_play/intro/introduction_01.txt'): +for character, line, direction in read_script(file): 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]) - pixel_ring.speak() + + led_on(speaker) + tts(voice, input_text, speaker) if action == 'listen_google_home': - listen() if action == 'music': @@ -96,10 +70,9 @@ for character, line, direction in read_script('scripts_play/intro/introduction_0 while playing: call(["aplay", "-D", speaker, "/usr/share/snips/congress.wav"]) playing = False - - - #pixel_ring.off() # Switch of the lights when done speaking + + led_off(speaker) sleep(0.2) # Add a short pause between the lines diff --git a/act_debug.py b/act_debug.py deleted file mode 100644 index 3b5659d..0000000 --- a/act_debug.py +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- - -# PLAY_ACT.py -# This script runs the play -# It is in a seperate file to enable the mechanism to detect the Google Home speaking, before continuing to the next line - -# Libraries -from config import characters, directions -from logic import tts, read_script,listen -from subprocess import call -import paho.mqtt.client as mqtt -import json -import sys -from time import sleep - -# Switch of LED's of speakers at the start of the play -#pixel_ring.off() - -import serial -from pixel_ring import pixel_ring -ser = serial.Serial('/dev/ttyACM0', 1000000) # Establish the connection on a specific port - -def led_on(speaker): - - 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() - - - -# Read the script and run the play - - -file = sys.argv[1] # get the chosen act passed by smart_speaker_theatre.py -led_off(speaker) - -for character, line, direction in read_script(file): - 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]) - #pixel_ring.speak() - led_on(speaker) - tts(voice, input_text, speaker) - led_off(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 - - - sleep(0.2) # Add a short pause between the lines - - -print('The act is done.') \ No newline at end of file diff --git a/logic.py b/logic.py index e0a000c..4ab1a86 100644 --- a/logic.py +++ b/logic.py @@ -58,8 +58,11 @@ from urllib.parse import urlencode, quote # For URL creation def tts(voice, input_text, speaker): + if speaker == "mono2": + volume_level = "amount:0.7" + if speaker == "mono3": - volume_level = "amount:0.5" + volume_level = "amount:0.7" else: volume_level = "amount:1.0" @@ -145,9 +148,7 @@ import serial from pixel_ring import pixel_ring ser = serial.Serial('/dev/ttyACM0', 1000000) # Establish the connection on a specific port -def led_on(speaker): - - +def led_on(speaker): if speaker == 'mono3': ser.write(b'3')