|
|
@ -9,13 +9,16 @@
|
|
|
|
# Libraries
|
|
|
|
# Libraries
|
|
|
|
import re
|
|
|
|
import re
|
|
|
|
from config import characters, directions
|
|
|
|
from config import characters, directions
|
|
|
|
from logic import tts, read_script, select_script, play_script
|
|
|
|
from logic import tts, read_script, select_script, led_on, led_off
|
|
|
|
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
|
|
|
|
import serial
|
|
|
|
|
|
|
|
from tuning import Tuning
|
|
|
|
|
|
|
|
import usb.core
|
|
|
|
|
|
|
|
import usb.util
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# === SETUP OF MQTT PART 1 ===
|
|
|
|
# === SETUP OF MQTT PART 1 ===
|
|
|
@ -32,10 +35,73 @@ def on_connect(client, userdata, flags, rc):
|
|
|
|
client.subscribe('hermes/intent/jocavdh:play_verdict') # to check for the intent to continue to the next act
|
|
|
|
client.subscribe('hermes/intent/jocavdh:play_verdict') # to check for the intent to continue to the next act
|
|
|
|
client.subscribe('hermes/hotword/default/detected')
|
|
|
|
client.subscribe('hermes/hotword/default/detected')
|
|
|
|
client.subscribe("hermes/asr/textCaptured")
|
|
|
|
client.subscribe("hermes/asr/textCaptured")
|
|
|
|
client.subscribe("hermes/dialogueManager/sessionQueued")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Set up serial connection with the microcontroller that controls the speaker LED's
|
|
|
|
# Set up serial connection with the microcontroller that controls the speaker LED's
|
|
|
|
ser = serial.Serial('/dev/ttyACM0', 1000000)
|
|
|
|
ser = serial.Serial('/dev/ttyACM0', 9600)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Function to do the play
|
|
|
|
|
|
|
|
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])
|
|
|
|
|
|
|
|
print(direction)
|
|
|
|
|
|
|
|
print(action)
|
|
|
|
|
|
|
|
led_on(ser, speaker)
|
|
|
|
|
|
|
|
tts(voice, input_text, speaker)
|
|
|
|
|
|
|
|
led_off(ser, speaker)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if action == 'listen_google_home':
|
|
|
|
|
|
|
|
dev = usb.core.find(idVendor=0x2886, idProduct=0x0018)
|
|
|
|
|
|
|
|
print('Wait for Google Home')
|
|
|
|
|
|
|
|
Mic_tuning = Tuning(dev)
|
|
|
|
|
|
|
|
VAD = Mic_tuning.is_voice()
|
|
|
|
|
|
|
|
counter= 0
|
|
|
|
|
|
|
|
voice_detected = 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while voice_detected == 1:
|
|
|
|
|
|
|
|
print('Google Home is Speaking')
|
|
|
|
|
|
|
|
sleep(4)
|
|
|
|
|
|
|
|
print(VAD)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VAD = Mic_tuning.is_voice()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if VAD == 1:
|
|
|
|
|
|
|
|
counter = 0
|
|
|
|
|
|
|
|
print('still speaking')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if VAD == 0:
|
|
|
|
|
|
|
|
counter+=1
|
|
|
|
|
|
|
|
print('silence detected')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if counter == 2:
|
|
|
|
|
|
|
|
print('no voice detected')
|
|
|
|
|
|
|
|
voice_detected = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sleep(0.5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print('Google Home is done')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if action == 'music':
|
|
|
|
|
|
|
|
print('play audioclip')
|
|
|
|
|
|
|
|
playing = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while playing:
|
|
|
|
|
|
|
|
call(["aplay", "-D", speaker, "/usr/share/snips/congress.wav"])
|
|
|
|
|
|
|
|
playing = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sleep(1) # Add a short pause between the lines
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print('The act is done.')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Function to control the LED's of the speakers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -43,15 +109,21 @@ ser = serial.Serial('/dev/ttyACM0', 1000000)
|
|
|
|
|
|
|
|
|
|
|
|
def on_wakeword(client, userdata, msg):
|
|
|
|
def on_wakeword(client, userdata, msg):
|
|
|
|
pixel_ring.think()
|
|
|
|
pixel_ring.think()
|
|
|
|
|
|
|
|
led_on(ser, 'mono1')
|
|
|
|
|
|
|
|
led_on(ser, 'mono3')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def on_asr_captured(client, userdata, msg):
|
|
|
|
|
|
|
|
pixel_ring.off()
|
|
|
|
|
|
|
|
led_off(ser, 'mono1')
|
|
|
|
|
|
|
|
led_off(ser, 'mono3')
|
|
|
|
|
|
|
|
|
|
|
|
# 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):
|
|
|
|
|
|
|
|
|
|
|
|
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')
|
|
|
|
play_script('scripts_play/debug/debug_02.txt')
|
|
|
|
print('The act is over.')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 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):
|
|
|
@ -81,6 +153,7 @@ client.message_callback_add('hermes/hotword/default/detected', on_wakeword)
|
|
|
|
client.message_callback_add('hermes/intent/jocavdh:play_intro', on_play_intro)
|
|
|
|
client.message_callback_add('hermes/intent/jocavdh:play_intro', on_play_intro)
|
|
|
|
client.message_callback_add('hermes/intent/jocavdh:play_question', on_play_question)
|
|
|
|
client.message_callback_add('hermes/intent/jocavdh:play_question', on_play_question)
|
|
|
|
client.message_callback_add('hermes/intent/jocavdh:play_verdict', on_play_verdict)
|
|
|
|
client.message_callback_add('hermes/intent/jocavdh:play_verdict', on_play_verdict)
|
|
|
|
|
|
|
|
client.message_callback_add('hermes/asr/textCaptured', on_asr_captured)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Keep checking for new MQTT messages
|
|
|
|
# Keep checking for new MQTT messages
|
|
|
|