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.

61 lines
1.8 KiB
Python

#!/usr/bin/env python
import json, random, os, subprocess
6 years ago
from pprint import pprint
from time import sleep
from LEDfunctions import *
def vu_2_leds(color):
while True:
data = play_process.stdout.readline()
if not data:
pixels.clear() # make LEDs dark
pixels.show()
break
data = data.rstrip()
if data.endswith("%"):
vu = float(data[:-1][-3:])/100 # 0-100
leds_color_intensity(color, vu)
6 years ago
# open announcer.json files
pwd = os.path.dirname( os.path.realpath(__file__) ) + "/"
announcer_f = open(pwd + "announcer.json", "r").read()
announcer = json.loads(announcer_f)
# print(announcer)
position_file = open(pwd + "announcements_position.txt", "r")
#choosing next message in sequence
msg_sf_len=len( announcer['messages'] )
position= (int( position_file.read() ) ) + 1
if position == msg_sf_len:
position = 0
print(position)
position_file = open(pwd + "announcements_position.txt", "w")
position_file.write(str(position))
position_file.close()
print ("position", position)
6 years ago
# ANNOUNCER PART
# msg = random.choice( announcer['messages'] ) #choosing a random intro.
6 years ago
sound_dir = pwd + "Audio_recordings/Announcements/"
intro_sf = sound_dir + random.choice( announcer['introductions'] )
msg_sf = sound_dir + announcer['messages'][position]
6 years ago
print(intro_sf, msg_sf)
#play audio
print(intro_sf)
#play_process = subprocess.Popen(["aplay", intro_sf, "-f", "cd", "--vumeter=mono"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
os.system('play -q "{}" gain 5'.format(intro_sf) )
play_process = subprocess.Popen(["aplay", msg_sf, "-f", "cd", "--vumeter=mono"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
vu_2_leds(color_announcer)
#os.system('play -q "{}" gain 1'.format(msg_sf) )