-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
73 lines (52 loc) · 1.62 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
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
#!/usr/bin/env python
import os
import signal
import time
from respeaker.bing_speech_api import BingSpeechAPI
from respeaker.microphone import Microphone
from respeaker.player import Player
from worker_weather import Worker
BING_KEY = '3560976f779d4095a7109bc55a3b0c79'
mic = Microphone()
bing = BingSpeechAPI(key=BING_KEY)
player = Player(mic.pyaudio_instance)
worker = Worker()
worker.set_player(player)
worker.set_tts(bing)
# script_dir = os.path.dirname(os.path.realpath(__file__))
# hello = os.path.join(script_dir, 'hello.wav')
mission_completed = False
awake = False
awake_count = 0
mission_completed = False
# awake = False
awake = True
def handle_int(sig, frame):
global mission_completed
print "terminating..."
# pixel_ring.off()
mission_completed = True
mic.close()
player.close()
worker.stop()
signal.signal(signal.SIGINT, handle_int)
worker.start()
# pixel_ring.set_color(r=0, g=0, b=100)
# time.sleep(3)
# player.play(hello)
while not mission_completed:
if mic.wakeup('respeaker'):
print "wakeup, please speak your command"
time.sleep(0.5)
data = mic.listen()
data = b''.join(data)
# recognize speech using Microsoft Bing Voice Recognition
try:
text = bing.recognize(data, language='en-US')
print('Bing:' + text.encode('utf-8'))
worker.push_cmd(text)
worker.wait_done()
if text.find('shut down') > -1:
handle_int(0,0)
except Exception as e:
print("Could not request results from Microsoft Bing Voice Recognition service; {0}".format(e))