@@ -332,30 +332,9 @@ class ResponsiveRecognizer(speech_recognition.Recognizer):
332332 def __init__ (self , loop , watchdog = None ):
333333 self .loop = loop
334334 self ._watchdog = watchdog or (lambda : None ) # Default to dummy func
335- self .config = Configuration .get ()
336- listener_config = self .config .get ('listener' )
337- self .instant_listen = listener_config .get ("instant_listen" , False )
338- self .upload_url = listener_config ['wake_word_upload' ]['url' ]
339- self .upload_disabled = listener_config ['wake_word_upload' ]['disable' ]
340-
341- self .overflow_exc = listener_config .get ('overflow_exception' , False )
342335
343336 super ().__init__ ()
344337 self .audio = pyaudio .PyAudio ()
345- self .multiplier = listener_config .get ('multiplier' )
346- self .energy_ratio = listener_config .get ('energy_ratio' )
347-
348- # Check the config for the flag to save wake words, utterances
349- # and for a path under which to save them
350- self .save_utterances = listener_config .get ('save_utterances' , False )
351- self .save_wake_words = listener_config .get ('record_wake_words' , False )
352- self .save_path = listener_config .get ('save_path' , gettempdir ())
353- self .saved_wake_words_dir = join (self .save_path , 'mycroft_wake_words' )
354- if self .save_wake_words :
355- os .makedirs (self .saved_wake_words_dir , exist_ok = True )
356- self .saved_utterances_dir = join (self .save_path , 'mycroft_utterances' )
357- if self .save_utterances :
358- os .makedirs (self .saved_utterances_dir , exist_ok = True )
359338
360339 # Signal statuses
361340 self ._stop_signaled = False
@@ -366,22 +345,103 @@ def __init__(self, loop, watchdog=None):
366345 # identifier used when uploading wakewords to selene
367346 self ._account_id = None
368347
348+ @property
349+ def config (self ):
350+ return Configuration .get ()
351+
352+ @property
353+ def instant_listen (self ):
354+ listener_config = self .config .get ('listener' ) or {}
355+ return listener_config .get ("instant_listen" , False )
356+
357+ @property
358+ def overflow_exc (self ):
359+ listener_config = self .config .get ('listener' ) or {}
360+ return listener_config .get ('overflow_exception' , False )
361+
362+ @property
363+ def upload_url (self ):
364+ listener_config = self .config .get ('listener' ) or {}
365+ return listener_config ['wake_word_upload' ]['url' ]
366+
367+ @property
368+ def upload_disabled (self ):
369+ listener_config = self .config .get ('listener' ) or {}
370+ return listener_config ['wake_word_upload' ]['disable' ]
371+
372+ @property
373+ def multiplier (self ):
374+ listener_config = self .config .get ('listener' ) or {}
375+ return listener_config .get ('multiplier' )
376+
377+ @property
378+ def energy_ratio (self ):
379+ listener_config = self .config .get ('listener' ) or {}
380+ return listener_config .get ('energy_ratio' )
381+
382+ @property
383+ def save_utterances (self ):
384+ listener_config = self .config .get ('listener' ) or {}
385+ return listener_config .get ('save_utterances' , False )
386+
387+ @property
388+ def save_wake_words (self ):
389+ listener_config = self .config .get ('listener' ) or {}
390+ return listener_config .get ('record_wake_words' , False )
391+
392+ @property
393+ def save_path (self ):
394+ listener_config = self .config .get ('listener' ) or {}
395+ return listener_config .get ('save_path' , gettempdir ())
396+
397+ @property
398+ def saved_wake_words_dir (self ):
399+ path = join (self .save_path , 'mycroft_wake_words' )
400+ if self .save_wake_words :
401+ os .makedirs (path , exist_ok = True )
402+ return path
403+
404+ @property
405+ def saved_utterances_dir (self ):
406+ path = join (self .save_path , 'mycroft_utterances' )
407+ if self .save_wake_words :
408+ os .makedirs (path , exist_ok = True )
409+ return path
410+
411+ @property
412+ def recording_timeout (self ):
369413 # The maximum seconds a phrase can be recorded,
370414 # provided there is noise the entire time
371- self .recording_timeout = listener_config .get ('recording_timeout' , 10.0 )
415+ listener_config = self .config .get ('listener' ) or {}
416+ return listener_config .get ('recording_timeout' , 10.0 )
417+
418+ @property
419+ def recording_timeout_with_silence (self ):
372420 # The maximum time it will continue to record silence
373421 # when not enough noise has been detected
374- self .recording_timeout_with_silence = listener_config .get ('recording_timeout_with_silence' , 3.0 )
375- # mic meter settings, will write mic level to ipc, used by debug_cli
376- # NOTE: this writes a lot to disk, it can be problematic in a sd card if you don't use a tmpfs for ipc
422+ listener_config = self .config .get ('listener' ) or {}
423+ return listener_config .get ('recording_timeout_with_silence' , 3.0 )
424+
425+ @property
426+ def mic_level_file (self ):
377427 ipc = get_ipc_directory ()
378428 os .makedirs (ipc , exist_ok = True )
379- self .mic_level_file = os .path .join (ipc , "mic_level" )
380- self .mic_meter_ipc_enabled = listener_config .get ("mic_meter_ipc" , True )
429+ return os .path .join (ipc , "mic_level" )
381430
431+ @property
432+ def mic_meter_ipc_enabled (self ):
433+ # mic meter settings, will write mic level to ipc, used by debug_cli
434+ # NOTE: this writes a lot to disk
435+ # can be problematic in a sd card if you don't use a tmpfs for ipc
436+ listener_config = self .config .get ('listener' ) or {}
437+ return listener_config .get ("mic_meter_ipc" , True )
438+
439+ @property
440+ def test_ww_sec (self ):
382441 # The maximum audio in seconds to keep for transcribing a phrase
383442 # The wake word must fit in this time
384- self .test_ww_sec = listener_config .get ("test_ww_sec" , 3 )
443+ listener_config = self .config .get ('listener' ) or {}
444+ return listener_config .get ("test_ww_sec" , 3 )
385445
386446 @property
387447 def account_id (self ):
0 commit comments