File tree 3 files changed +17
-15
lines changed
3 files changed +17
-15
lines changed Original file line number Diff line number Diff line change 2
2
import os
3
3
import traceback
4
4
import logging
5
- import dictconfig
5
+ from logging import config
6
6
from google_speech import Speech
7
7
from subprocess import call
8
8
@@ -28,22 +28,22 @@ class OutputStyler:
28
28
BOLD = '\033 [1m'
29
29
UNDERLINE = '\033 [4m'
30
30
31
+
31
32
# Create a Console & Rotating file logger
32
- dictconfig .dictConfig (LOG_SETTINGS )
33
+ config .dictConfig (LOG_SETTINGS )
34
+
33
35
34
36
def log (func ):
35
37
def wrapper (* args , ** kwargs ):
36
38
try :
37
- logger .debug (func .__name__ )
39
+ logging .debug (func .__name__ )
38
40
func (* args , ** kwargs )
39
41
except Exception as e :
40
- logger .error (func .__name__ )
42
+ logging .error (func .__name__ )
41
43
traceback .print_exc (file = sys .stdout )
42
44
return wrapper
43
- return log
44
45
45
46
46
- @log
47
47
def assistant_response (text ):
48
48
"""
49
49
Assistant response in voice or/and in text
@@ -58,7 +58,7 @@ def assistant_response(text):
58
58
59
59
60
60
def user_speech_playback (text ):
61
- user_speech = str (OutputStyler .GREEN + 'You: ' + text )
61
+ user_speech = str (OutputStyler .GREEN + 'You: ' + text + ' \n ' )
62
62
sys .stdout .write (OutputStyler .BLUE + user_speech + OutputStyler .ENDC )
63
63
64
64
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ def __init__(self):
21
21
self .r = sr .Recognizer ()
22
22
self .words = None
23
23
24
+ @log
24
25
def run (self ):
25
26
self .words = self ._get_words ()
26
27
commands = self ._get_commands ()
@@ -37,7 +38,6 @@ def wake_up_check(self):
37
38
self .words = self .r .recognize_google (audio ).lower ()
38
39
except sr .UnknownValueError :
39
40
self .words = self ._get_words ()
40
-
41
41
if TRIGGERING_WORDS ['enable_jarvis' ] in self .words :
42
42
self ._wake_up_response ()
43
43
return True
@@ -51,6 +51,7 @@ def shutdown_check(self):
51
51
"""
52
52
if TRIGGERING_WORDS ['disable_jarvis' ] in self .words :
53
53
assistant_response ('Bye bye Sir. Have a nice day' )
54
+ logging .debug ('Application terminated gracefully.' )
54
55
sys .exit ()
55
56
56
57
@staticmethod
@@ -78,6 +79,7 @@ def _get_commands(self):
78
79
words_set = set (words )
79
80
return commands_set .intersection (words_set )
80
81
82
+ @log
81
83
def _execute_commands (self , commands ):
82
84
"""
83
85
Execute iteratively all the commands in the input dict.
@@ -112,4 +114,5 @@ def _record(self):
112
114
self .r .pause_threshold = SPEECH_RECOGNITION ['pause_threshold' ]
113
115
self .r .adjust_for_ambient_noise (source , duration = SPEECH_RECOGNITION ['ambient_duration' ])
114
116
audio_text = self .r .listen (source )
117
+
115
118
return audio_text
Original file line number Diff line number Diff line change 9
9
'class' : 'logging.StreamHandler' ,
10
10
'level' : 'INFO' ,
11
11
'formatter' : 'detailed' ,
12
- 'stream' : 'ext:// sys.stdout' ,
12
+ 'stream' : 'sys.stdout' ,
13
13
},
14
14
'file' : {
15
15
'class' : 'logging.handlers.RotatingFileHandler' ,
16
- 'level' : 'INFO ' ,
16
+ 'level' : 'DEBUG ' ,
17
17
'formatter' : 'detailed' ,
18
- 'filename' : '/var/logs /jarvis.log' ,
18
+ 'filename' : '/var/log /jarvis.log' ,
19
19
'mode' : 'a' ,
20
20
'maxBytes' : 10000000 ,
21
21
'backupCount' : 3 ,
22
22
},
23
23
},
24
24
'formatters' : {
25
25
'detailed' : {
26
- #format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
27
- 'format' : '%(asctime)s %(module)-17s line:%(lineno)-4d ' \
28
- '%(levelname)-8s %(message)s' ,
29
- },
26
+ 'format' : '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
27
+ },
28
+ }
30
29
}
31
30
32
31
You can’t perform that action at this time.
0 commit comments