-
Notifications
You must be signed in to change notification settings - Fork 1
/
alexa.py
185 lines (135 loc) · 4.91 KB
/
alexa.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
# alexa.py
"""This is the definition of the API class for Alexa Voice Service."""
import sys
import requests
from waitress import serve
from flask import Flask
from flask_ask import Ask, statement, question
from remote_controller.command_handler import CommandHandler
app = Flask(__name__)
ask = Ask(app, '/')
hostname = 'http://10.0.0.10:55555'
# Event to start interaction with the controller
# NOTE: just for spanish
@ask.launch
def start_skill():
welcome_message = '¿Qué le digo a la tele?'
return question(welcome_message)
# Intent for help with the interaction
@ask.intent('AMAZON.HelpIntent')
def help_intent():
return statement('Puedes enviar comandos como: encender, canal 10, sube el volumen, etcétera.')
# Definition of ALL the basic command interactions
@ask.intent('PowerIntent')
def power_intent():
request = {'raw-command': False, 'command': 'POWER'}
requests.post(hostname, json=request)
return statement('Listo')
@ask.intent('OKIntent')
def ok_intent():
request = {'raw-command': False, 'command': 'OK'}
requests.post(hostname, json=request)
return statement('Listo')
@ask.intent('UndoIntent')
def undo_intent():
request = {'raw-command': False, 'command': 'UNDO'}
requests.post(hostname, json=request)
return statement('Listo')
@ask.intent('ListIntent')
def list_intent():
request = {'raw-command': False, 'command': 'LIST'}
requests.post(hostname, json=request)
return statement('Listo')
@ask.intent('BackIntent')
def back_intent():
request = {'raw-command': False, 'command': 'BACK'}
requests.post(hostname, json=request)
return statement('Listo')
@ask.intent('InfoIntent')
def info_intent():
request = {'raw-command': False, 'command': 'INFO'}
requests.post(hostname, json=request)
return statement('Listo')
@ask.intent('ExitIntent')
def exit_intent():
request = {'raw-command': False, 'command': 'EXIT'}
requests.post(hostname, json=request)
return statement('Listo')
@ask.intent('MenuIntent')
def menu_intent():
request = {'raw-command': False, 'command': 'MENU'}
requests.post(hostname, json=request)
return statement('Listo')
@ask.intent('MuteIntent')
def mute_intent():
request = {'raw-command': False, 'command': 'MUTE'}
requests.post(hostname, json=request)
return statement('Listo')
@ask.intent('SettingsIntent')
def settings_intent():
request = {'raw-command': False, 'command': 'SETTINGS'}
requests.post(hostname, json=request)
return statement('Listo')
@ask.intent('InputIntent')
def input_intent(value):
if value is not None:
request = {'raw-command': False, 'command': 'INPUT {}'.format(value)}
else:
request = {'raw-command': False, 'command': 'INPUT'}
requests.post(hostname, json=request)
return statement('Listo')
@ask.intent('ScreenRatioIntent')
def screen_ratio_intent():
request = {'raw-command': False, 'command': 'SCREEN_RATIO'}
requests.post(hostname, json=request)
return statement('Listo')
@ask.intent('MoveUpIntent')
def move_up_intent():
request = {'raw-command': False, 'command': 'MOVE_UP'}
requests.post(hostname, json=request)
return statement('Listo')
@ask.intent('MoveDownIntent')
def move_down_intent():
request = {'raw-command': False, 'command': 'MOVE_DOWN'}
requests.post(hostname, json=request)
return statement('Listo')
@ask.intent('MoveLeftIntent')
def move_left_intent():
request = {'raw-command': False, 'command': 'MOVE_LEFT'}
requests.post(hostname, json=request)
return statement('Listo')
@ask.intent('MoveRightIntent')
def move_right_intent():
request = {'raw-command': False, 'command': 'MOVE_RIGHT'}
requests.post(hostname, json=request)
return statement('Listo')
@ask.intent('ChannelIntent')
def channel_intent(channel):
request = {'raw-command': False, 'command': 'CHANNEL {}'.format(channel)}
requests.post(hostname, json=request)
return statement('Listo')
@ask.intent('VolumeUpIntent')
def volume_up_intent(value):
if value is not None:
request = {'raw-command': False, 'command': 'VOLUME_UP {}'.format(value)}
else:
request = {'raw-command': False, 'command': 'VOLUME_UP'}
requests.post(hostname, json=request)
return statement('Listo')
@ask.intent('VolumeDownIntent')
def volume_down_intent(value):
if value is not None:
request = {'raw-command': False, 'command': 'VOLUME_DOWN {}'.format(value)}
else:
request = {'raw-command': False, 'command': 'VOLUME_DOWN'}
requests.post(hostname, json=request)
return statement('Listo')
if __name__ == '__main__':
if len(sys.argv) < 2:
print('Please enter a device name, aborting...')
else:
command_handler = CommandHandler(sys.argv[1], False)
command_handler.load()
print('Starting on device: {}'.format(sys.argv[1]))
# Server to run, definition of the port
serve(app, host='localhost', port=33333)