Sfoglia il codice sorgente

better tts cache location, readmen doc

Martin 7 anni fa
parent
commit
2e012e7455
3 ha cambiato i file con 9 aggiunte e 10 eliminazioni
  1. 4 3
      README.md
  2. 1 0
      voice_control/conf.py
  3. 4 7
      voice_control/output/audio_output.py

+ 4 - 3
README.md

@@ -7,13 +7,14 @@ Linux:
 
     aptitude build-dep python-pygame
 
-
 PortAudio: 
     linux: http://portaudio.com/download.html, download, configure, make, make install
     osx: brew install portaudio
 
 add user to audio group: sudo usermod -a -G audio martin
 
-set up a virtualenv and install python requirements
+set up a virtualenv, install python requirements, and link to a speech_recognition and snowboy dist folder from inside the venv python lib folder
 
-ensure that the root of this folder and the parent of speech_recognition are available in PYTHONPATH
+environment variables:
+- PYTHONPATH (set to current dir)
+- GOOGLE_APPLICATION_CREDENTIALS (set to gcloud credentials path)

+ 1 - 0
voice_control/conf.py

@@ -15,6 +15,7 @@ SPEECH_RECOGNITION_MIN_ENERGY_LEVEL = 400
 # Audio output
 SOUND_OUTPUT_ENABLED = False
 CLIPS_FOLDER = os.path.join(RESOURCES_FOLDER, 'clips')
+TTS_CACHE_FOLDER = '/tmp/vc-tts-cache'
 
 # Slack I/O
 SLACK_BOT_API_KEY = None

+ 4 - 7
voice_control/output/audio_output.py

@@ -7,14 +7,11 @@ from gtts import gTTS
 import pygame.mixer
 
 import base
-from voice_control.conf import CLIPS_FOLDER
+from voice_control.conf import CLIPS_FOLDER, TTS_CACHE_FOLDER
 
 _CLIP_DATA_CACHE = {}
-if not os.path.isdir('/tmp/snowboy'):
-    os.mkdir('/tmp/snowboy')
-TMP_DIR = '/tmp/snowboy/tts-cache'
-if not os.path.isdir(TMP_DIR):
-    os.mkdir(TMP_DIR)
+if not os.path.isdir(TTS_CACHE_FOLDER):
+    os.makedirs(TTS_CACHE_FOLDER)
 
 class Clips(object):
     SUCCESS = 'ding.wav'
@@ -47,7 +44,7 @@ def _play_clip(clip):
 class AudioOutput(base.Base):
     def tts(self, msg):
         tts_hash = hashlib.md5(msg.lower()).hexdigest()
-        cache_fname = os.path.join(TMP_DIR, tts_hash) + '.mp3'
+        cache_fname = os.path.join(TTS_CACHE_FOLDER, tts_hash) + '.mp3'
         if os.path.isfile(cache_fname):
             _play(cache_fname, True)
             return