forked from fossasia/susi_linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_generator.py
190 lines (153 loc) · 6.39 KB
/
config_generator.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
""" Config Generator script for Susi Hardware. Run this script and input options
to generate a file for default services for your SUSI Hardware Device
"""
import json_config
import requests
from pathlib import Path
import os
from importlib import util
import sys
config = json_config.connect('config.json')
def is_valid(email, password):
""" Method to Validate SUSI Login Details
:param email: SUSI Sign-in email
:param password: SUSI Sign-in password
:return: boolean to indicate if details are valid
"""
print('Checking the validity of login details ....')
params = {
'login': email,
'password': password
}
sign_in_url = 'http://api.susi.ai/aaa/login.json?type=access-token'
api_response = requests.get(sign_in_url, params)
if api_response.status_code == 200:
return True
else:
return False
def setup_wake_button():
try:
import RPi.GPIO
print("\nDevice supports RPi.GPIO")
# choice = input("Do you wish to enable hardware wake button? (y/n) ")
choice = sys.argv[4]
if choice == 'y':
config['WakeButton'] = 'enabled'
config['Device'] = 'RaspberryPi'
else:
config['WakeButton'] = 'disabled'
except ImportError:
print("\nThis device does not support RPi.GPIO")
config['WakeButton'] = 'not available'
except RuntimeError:
print("\nThis device does not support RPi.GPIO")
config['WakeButton'] = 'not available'
def set_extras():
""" Method for setting miscellaneous configuration parameters.
:return: None
"""
config.setdefault('data_base_dir', os.path.dirname(os.path.abspath(__file__)))
config.setdefault('flite_speech_file_path', 'extras/cmu_us_slt.flitevox')
config.setdefault('detection_bell_sound', 'extras/detection-bell.wav')
config.setdefault('problem_sound', 'extras/problem.wav')
config.setdefault('recognition_error_sound', 'extras/recognition-error.wav')
def request_hotword_choice():
""" Method to request user for default Hotword Engine and configure it in settings.
"""
try:
print("Checking for Snowboy Availability...")
snowboy_available = util.find_spec('snowboy')
found = snowboy_available is not None
except ImportError:
print("Some Error Occurred.Snowboy not configured properly.\nUsing PocketSphinx as default engine for Hotword. Run this script again to change")
found = False
config['hotword_engine'] = 'PocketSphinx'
if found is True:
print("Snowboy is available on this platform")
# choice = input("Do you wish to use Snowboy as default Hotword Detection Engine (Recommended). (y/n) ")
choice = sys.argv[3]
if choice == 'y':
config['hotword_engine'] = 'Snowboy'
print('\n Snowboy set as default Hotword Detection Engine \n')
else:
config['hotword_engine'] = 'pocket_sphinx'
print('\n PocketSphinx set as default Hotword Detection Engine \n')
else:
print('\n Snowboy not configured Properly\n')
config['hotword_engine'] = 'pocket_sphinx'
print('\n PocketSphinx set as default Hotword Detection Engine \n')
def request_stt_choice():
""" Method for setting default Speech Recognition Service.
:return: None
"""
try:
# choice = int(input('Which Speech Recognition Service do you wish to use? Press number or enter for default.\n'
# '1. Google Voice Recognition (default)\n'
# '2. IBM Watson\n'
# '3. Bing Speech API\n'
# '4. PocketSphinx(offline) \n'))
choice = sys.argv[1]
print(choice)
if choice == 'google':
config['default_stt'] = 'google'
elif choice == 'ibm':
config['default_stt'] = 'watson'
print('For using IBM Watson. You need API keys for IBM Watson Speech to Text Service'
'Please input credentials')
username = input('Enter Username')
password = input('Enter Password')
config['watson_stt_config']['username'] = username
config['watson_stt_config']['password'] = password
config['watson_stt_config']['voice'] = 'en-US_AllisonVoice'
elif choice == 'bing':
config['default_stt'] = 'bing'
print('For using Bing Speech API, you need an API key')
key = input('Enter Bing Speech API Key')
config['bing_speech_api_key'] = key
elif choice == 'sphinx':
config['default_stt'] = 'pocket_sphinx'
else:
raise ValueError
except ValueError:
print('Invalid Input. Using default Voice Recognition Service')
config['default_stt'] = 'google'
print("\nSpeech to Text configured successfully\n")
def request_tts_choice():
""" Method for setting default Text to Speech Service
:return: None
"""
try:
# choice = int(input('Which Text to Speech Service do you wish to use? Press number or enter for default.\n'
# '1. Google Text to Speech (default)\n'
# '2. Flite TTS (offline)\n'
# '3. IBM Watson\n'))
choice = sys.argv[2]
if choice == 'google':
config['default_tts'] = 'google'
elif choice == 'flite':
config['default_tts'] = 'flite'
elif choice == 'ibm':
config['default_tts'] = 'watson'
print('For using IBM Watson. You need API keys for IBM Watson Text to Speech Service'
'Please input credentials')
username = input('Enter Username')
password = input('Enter Password')
config['watson_tts_config']['username'] = username
config['watson_tts_config']['password'] = password
else:
raise ValueError
except ValueError:
print('Invalid input. Using default Text to Speech Service')
config['default_tts'] = 'google'
print("\nSpeech to Text configured successfully\n")
set_extras()
# print(len(sys.argv))
print("Setup Speech to Text Service\n")
request_stt_choice()
print("Setup Text to Speech Service\n")
request_tts_choice()
print("Setup Hotword Detection Engine\n")
request_hotword_choice()
print("Setup Wake Button\n")
setup_wake_button()
print("Run SUSI by 'python3 -m main'")