Repository: MycroftAI/mycroft-core

Issue:
add config entry for path to save output files
# How to submit an Issue to a Mycroft repository
## Be clear about the software, hardware and version you are running
* I'm running a picroft
* With latest unstable
* With custom Wake Word

## Try to provide steps that we can use to replicate the Issue

Turn on saving of wake words and audio clips (set both of these to "true"):
    "record_wake_words": false,
    "save_utterances": false,

only over here: https://github.com/MycroftAI/mycroft-core/blob/master/mycroft/configuration/mycroft.conf 
does it mention where it saves these to.  
This should be a configurable path, much like the upload URL is, for either/both of these.  Perhaps "default_save_path" or something less awkward.  



Discussion:
Yeah good call.

Would a single configurable path with two sub-directories be sufficient?
- `mycroft_wake_words`
- `mycroft_utterances`
yeah seems reasonable to me.
Another thing to consider here is that they would need to be writable by the `mycroft` user, so the directories would need the correct ownership permissions. 

Another thing to consider is that even though saving Wake Words and Utterances is off by default, I could see this potentially filling disk space over time. I've seen several cases where `/var/log/mycroft` contains hundreds of Mb of logs, even with `logrotate`. Do we need to put in place any checks to protect disk space, particularly on the `picroft` or `mark` platforms? 
Since it's off by default and would require direct cli changes, I don't think it should require disk protections.  Turning it on means you've got enough knowledge to get to the system and handle basic stuff.  A warning in the config might be useful by the option. If this is something coming to web config or turned on by default then this would be worth revisiting.  

The permissions issue is another good point, but would be covered in the logs.  Again, though, if they're doing cli level work to get this set they can get to their logs, and should be able to see the issue.  
permissions would only apply to the mark1/picroft, otherwise we can not assume anything regarding the installs/users, i don't like to make assumptions about how the users are using it, i don't think we should touch permissions at all. 

I might install mycroft as a standalone user, in main user account, or as root. i have done all these at some point

a warning in mark1/picroft docs should be enough


Resolving patch:
diff --git a/mycroft/client/speech/mic.py b/mycroft/client/speech/mic.py
--- a/mycroft/client/speech/mic.py
+++ b/mycroft/client/speech/mic.py
@@ -222,12 +222,18 @@ def __init__(self, wake_word_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.saved_wake_words_dir = join(gettempdir(), 'mycroft_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 = []
@@ -553,8 +559,6 @@ def _wait_until_wake_word(self, source, sec_per_buffer, emitter):
                         # 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(
@@ -647,7 +651,10 @@ def listen(self, source, emitter, stream=None):
         if self.save_utterances:
             LOG.info("Recording utterance")
             stamp = str(datetime.datetime.now())
-            filename = "/tmp/mycroft_utterance%s.wav" % stamp
+            filename = "/{}/{}.wav".format(
+                self.saved_utterances_dir,
+                stamp
+            )
             with open(filename, 'wb') as filea:
                 filea.write(audio_data.get_wav_data())
             LOG.debug("Thinking...")


Test patch: