/
test.py
57 lines (44 loc) · 1.1 KB
/
test.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
from __future__ import print_function
from subprocess import Popen, call
import json
import wit
from access_token import ACCESS_TOKEN
playlists = {
'full-day_list': 'spotify:user:1146628823:playlist:6TSA3CY3vwcWrZSvG8Zgwi',
'jazz': 'spotify:user:1146628823:playlist:1YEoE6AslVyAA6CTXv20zn'
}
def start_spotify():
playlist = playlists['full-day_list']
p = Popen(['spotify'])
if p.poll() is None:
p.wait()
call(
[
'spotify-remote', 'play',
playlist
]
)
def start_vlc():
print('Sorry VLC is not installed')
def query():
access_token = ACCESS_TOKEN
wit.init()
response = json.loads(
wit.voice_query_auto(access_token)
)
print('Response: {}'.format(response))
wit.close()
return response
intents = {
'start_spotify': start_spotify,
'start_vlc': start_vlc
}
def handle_response(response):
print('RESPONSE:', response)
#intents[response['outcomes'][0]['intent']]()
def main():
while True:
response = query()
handle_response(response)
if __name__ == '__main__':
main()