-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrol.py
72 lines (59 loc) · 1.94 KB
/
control.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import RPi.GPIO as GPIO
import time
import random
import simpleaudio as sa
from magic import assist
from google.cloud import texttospeech
GPIO.setmode(GPIO.BCM)
PARTY_PIN = 16
ASSISTANT_PIN = 19
SORTING_PIN = 27 # TODO
BUTTON_PIN = 20
TEAM_NAMES = ["Hardest Hat", "Dialog Revolution"]
GPIO.setup(PARTY_PIN, GPIO.IN)
GPIO.setup(ASSISTANT_PIN, GPIO.IN)
GPIO.setup(SORTING_PIN, GPIO.IN)
GPIO.setup(BUTTON_PIN, GPIO.IN)
clientT2S = texttospeech.TextToSpeechClient()
voice = texttospeech.types.VoiceSelectionParams(
language_code='en-US',
ssml_gender=texttospeech.enums.SsmlVoiceGender.NEUTRAL)
audio_config = texttospeech.types.AudioConfig(
audio_encoding=texttospeech.enums.AudioEncoding.LINEAR16)
was_sorting = False
def sorting_mode():
team_name = random.choice(TEAM_NAMES)
synthesis_input = texttospeech.types.SynthesisInput(text=team_name)
response = clientT2S.synthesize_speech(synthesis_input, voice, audio_config)
wave_obj = sa.WaveObject(response.audio_content, 1, 2, 22050)
play_obj = wave_obj.play()
play_obj.wait_done()
def party_mode():
# TODO light up LEDs
wave_obj = sa.WaveObject.from_wave_file("/home/pi/party_audio.wav") # TODO filepath
play_obj = wave_obj.play()
while GPIO.input(PARTY_PIN) == GPIO.HIGH
time.sleep(0.2)
play_obj.stop()
print("Starting the awesome hat control!")
while True:
if GPIO.input(PARTY_PIN) == GPIO.HIGH: # Upwards
print("PARTY")
party_mode()
elif GPIO.input(ASSISTANT_PIN) == GPIO.HIGH: # Upwards
print("ASSISTANT MODE")
# one run of recording, sending, answering (blocking)
assist()
elif GPIO.input(SORTING_PIN) == GPIO.HIGH: # Upwards
print("SORTING MODE")
if was_sorting:
time.sleep(1)
continue
sorting_mode()
was_sorting = True
continue
else:
print("No mode active")
time.sleep(1)
was_sorting = False
GPIO.cleanup()