Add path checks
@@ -222,13 +222,18 @@ class ResponsiveRecognizer(speech_recognition.Recognizer):
self.audio = pyaudio.PyAudio()
self.multiplier = listener_config.get('multiplier')
self.energy_ratio = listener_config.get('energy_ratio')
- # check the config for the flag to save wake words.
+ # Check the config for the flag to save wake words, utterances
+ # and for a path under which to save them
self.save_utterances = listener_config.get('save_utterances', False)
-
- self.save_wake_words = listener_config.get('record_wake_words')
+ self.save_wake_words = listener_config.get('record_wake_words', False)
self.save_path = listener_config.get('save_path', gettempdir())
self.saved_wake_words_dir = join(self.save_path, 'mycroft_wake_words')
+ if self.save_wake_words and not isdir(self.saved_wake_words_dir):
+ os.mkdir(self.saved_wake_words_dir)
+ self.saved_utterances_dir = join(self.save_path, 'mycroft_utterances')
+ if self.save_utterances and not isdir(self.saved_utterances_dir):
+ os.mkdir(self.saved_utterances_dir)
self.upload_lock = Lock()
self.filenames_to_upload = []
@@ -554,8 +559,6 @@ class ResponsiveRecognizer(speech_recognition.Recognizer):
# Save wake word locally
audio = self._create_audio_data(byte_data, source)
mtd = self._compile_metadata()
- if not isdir(self.saved_wake_words_dir):
- os.mkdir(self.saved_wake_words_dir)
module = self.wake_word_recognizer.__class__.__name__
fn = join(
@@ -648,8 +651,8 @@ class ResponsiveRecognizer(speech_recognition.Recognizer):
if self.save_utterances:
LOG.info("Recording utterance")
stamp = str(datetime.datetime.now())
- filename = "/{}/mycroft_utterances/{}.wav".format(
- self.save_path,
+ filename = "/{}/{}.wav".format(
+ self.saved_utterances_dir,
stamp
)
with open(filename, 'wb') as filea:
