-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathmain.py
47 lines (35 loc) · 1.52 KB
/
main.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
import helper
import authorization
import alexa_device
__author__ = "NJC"
__license__ = "MIT"
__version__ = "0.2"
def user_input_loop(alexa_device):
""" This thread initializes a voice recognition event based on user input. This function uses command line
input for interacting with the user. The user can start a recording, or quit if desired.
This is currently the "main" thread for the device.
"""
# While the stop event is not set
while True:
# Prompt user to press enter to start a recording, or q to quit
text = input("Press enter anytime to start recording (or 'q' to quit).")
# If 'q' is pressed
if text == 'q':
# Set stop event and break out of loop
alexa_device.close()
break
# If enter was pressed (and q was not)
# Get raw audio from the microphone
alexa_device.user_initiate_audio()
if __name__ == "__main__":
# Load configuration file (contains the authorization for the user and device information)
config = helper.read_dict('config.dict')
# Check for authorization, if none, initialize and ask user to go to a website for authorization.
if 'refresh_token' not in config:
print("Please go to http://localhost:5000")
authorization.get_authorization()
config = helper.read_dict('config.dict')
# Create alexa device
alexa_device = alexa_device.AlexaDevice(config)
user_input_loop(alexa_device)
print("Done")