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.

79 lines
1.6 KiB
Python

5 years ago
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# PLAY_ACT.py
# This script runs the play
5 years ago
5 years ago
# Libraries
from config import characters, directions
5 years ago
from logic import tts, read_script,listen
from subprocess import call
5 years ago
import paho.mqtt.client as mqtt
import json
import sys
5 years ago
from time import sleep
# Switch of LED's of speakers at the start of the play
#pixel_ring.off()
5 years ago
import serial
from pixel_ring import pixel_ring
5 years ago
ser = serial.Serial('/dev/ttyACM0', 9600) # Establish the connection on a specific port
5 years ago
def led_on(speaker):
5 years ago
5 years ago
if speaker == 'mono3':
5 years ago
ser.write(b'H')
5 years ago
if speaker == 'mono1':
5 years ago
ser.write(b'H')
5 years ago
if speaker == 'mono2':
pixel_ring.speak()
5 years ago
def led_off(speaker):
5 years ago
if speaker == 'mono3':
5 years ago
ser.write(b'L')
5 years ago
if speaker == 'mono1':
5 years ago
ser.write(b'L')
5 years ago
if speaker == 'mono2':
pixel_ring.off()
5 years ago
# Read the script and run the play
5 years ago
5 years ago
file = sys.argv[1] # get the chosen act passed by smart_speaker_theatre.py
5 years ago
for character, line, direction in read_script(file):
5 years ago
input_text = line
voice = characters.get(character)[0]
speaker = characters.get(character)[1]
action = directions.get(direction[0])
5 years ago
led_on(speaker)
5 years ago
tts(voice, input_text, speaker)
if action == 'listen_google_home':
listen()
5 years ago
if action == 'music':
5 years ago
print('play audioclip')
playing = True
while playing:
call(["aplay", "-D", speaker, "/usr/share/snips/congress.wav"])
playing = False
5 years ago
led_off(speaker)
sleep(0.2) # Add a short pause between the lines
5 years ago
print('The act is done.')