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

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