#!/usr/bin/env python import json, random, os, subprocess 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) def leds_start_stop(color): # for pirate while True: data = play_process.stdout.readline() data = data.rstrip() print('data:',data) print('process:', play_process.stdout.readline()) #_handle_exitstatus leds_pirate_bounce(color_pirate) # open json files pwd = os.path.dirname( os.path.realpath(__file__) ) + "/" oracle_f = open(pwd + "guru.json", "r").read() oracle = json.loads(oracle_f) rebel_f = open(pwd + "rebel.json", "r").read() rebel = json.loads(rebel_f) # GURU PART keys = list( oracle.keys()) part = random.choice(keys) # choose: Repeat OR Ask Yourself print(part) sound_dir = pwd + "Audio_recordings/" + oracle[part]['title'] + "/" intro = random.choice(oracle[part]['introductions']) intro_txt = intro[0] intro_sound = sound_dir + intro[1] print('Intro:', intro_txt, intro_sound) play_process = subprocess.Popen(["aplay", intro_sound, "-f", "cd", "--vumeter=mono"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) vu_2_leds(color_guru) # REBEL reply rebel_run = random.choice([True, False]) # shall the rebel enter?? if rebel_run is True: rebel_reply_snippet = intro[2] # comes from guru/oracle dictionary rebel_reply = random.choice( rebel[part] ) rebel_sentence = rebel_reply.format(rebel_reply_snippet) # play msg for i in range( random.randint(1,4) ): sleep( random.randint(1,3) ) msg = random.choice(oracle[part]['messages']) msg_txt = msg[0] msg_sound = sound_dir + msg[1] print('MSG:', msg_txt, msg_sound) play_process = subprocess.Popen(["aplay", msg_sound, "-f", "cd", "--vumeter=mono"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) vu_2_leds(color_guru) # rebel text to speech if rebel_run is True: print('rebel sentence:', rebel_sentence) #rebel_cmd = 'echo "{}" | espeak -ven+whisper -s 150'.format(rebel_sentence) #os.system(rebel_cmd) # TO DO play_process = subprocess.Popen(["espeak", rebel_sentence, "-ven+whisper", "-s", "150"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) leds_pirate_bounce(color_pirate) # leds_start_stop(color_pirate)