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.

53 lines
1.5 KiB
Python

#!/usr/bin/env python3
import json, random, os
from pprint import pprint
from time import sleep
# open json files
oracle_f = open("oracle.json", "r").read()
oracle = json.loads(oracle_f)
rebel_f = open("rebel.json", "r").read()
rebel = json.loads(rebel_f)
# choose oracle part
keys = list( oracle.keys())
part = random.choice(keys)
print(part)
intro = random.choice(oracle[part]['introductions'])
intro_txt = intro[0]
intro_sound = "oracle/" + intro[1]
print('Intro:', intro_txt, intro_sound)
os.system("play -q {} gain 10 chorus 0.7 0.9 100 0.5 5 2 -t".format(intro_sound) )
# find rebel_key that matches oracle's intro_txt
rebel_key = None
for key in rebel.keys():
print(key, intro_txt.lower())
if key in intro_txt.lower():
rebel_key = key
break
else:
rebel_key = 'none'
# choose the rebel sentence
rebel_sentence = random.choice(rebel[rebel_key])
if "{}" in rebel_sentence:
rebel_sentence = rebel_sentence.format( (intro_txt.lower()).replace('me', 'you') )
print('rebel_key:', rebel_key)
print(rebel_sentence)
# play msg
for i in range(3):
sleep(2)
msg = random.choice(oracle[part]['messages'])
msg_txt = msg[0]
msg_sound = "oracle/" + msg[1] # oracle is the directory with the sound files
print('MSG:', msg_txt)
os.system("play -q {} gain 10 chorus 0.7 0.9 100 0.5 5 2 -t ".format(msg_sound) )
# rebel text to speech
print('rebel sentence:', rebel_sentence)
os.system('echo "{}" | espeak -ven+whisper -s 90'.format(rebel_sentence) )