You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.5 KiB
Python
60 lines
1.5 KiB
Python
#!/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
|
|
|
|
|
|
|
|
# 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.')
|