-
Notifications
You must be signed in to change notification settings - Fork 1
/
Blue.py
69 lines (44 loc) · 1.76 KB
/
Blue.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
from util.res import *
import speech_recognition as sr
from skills import check_skills
from util import setup
from config_server import start_webserver
from multiprocessing import Process,freeze_support
import app_server
def listen():
print("listening...")
voice_command = ""
try:
with sr.Microphone() as source:
data = r.record(source,duration=5)
voice_command = r.recognize_google(data,language=get_locale())
return voice_command
except Exception as e:
if e.__class__.__name__ != "UnknownValueError":
raise KeyboardInterrupt
if __name__ == '__main__':
auto_chdir_to_file_root()
#make sure the user have choosen a hot word
setup.check_files_integrity()
hot_word = setup.get_hot_word()
#start configuration server
freeze_support()
web_proc = Process(target=start_webserver)
web_proc.start()
#start app handling server
app_proc = app_server.initialize()
#init voice recognizer
try:
r = sr.Recognizer()
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source)
while True:
voice_command = listen()
if voice_command != None:
print(voice_command)
if(hot_word in voice_command):
voice_command = voice_command.replace(hot_word,"")
if not check_skills(voice_command):
print("Je ne sais pas encore faire cela")
except KeyboardInterrupt:
perror("No desktop microphone found or microphone listening loop manually disabled, you must use the android app.")