|
@@ -45,27 +45,24 @@ def _play_clip(clip):
|
|
|
return
|
|
return
|
|
|
|
|
|
|
|
class AudioOutput(base.Base):
|
|
class AudioOutput(base.Base):
|
|
|
- def tts(self, text):
|
|
|
|
|
- if not text:
|
|
|
|
|
- return
|
|
|
|
|
-
|
|
|
|
|
- tts_hash = hashlib.md5(text.lower()).hexdigest()
|
|
|
|
|
|
|
+ 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(TMP_DIR, tts_hash) + '.mp3'
|
|
|
if os.path.isfile(cache_fname):
|
|
if os.path.isfile(cache_fname):
|
|
|
_play(cache_fname, True)
|
|
_play(cache_fname, True)
|
|
|
return
|
|
return
|
|
|
|
|
|
|
|
- tts_stream = gTTS(text=text, lang='en')
|
|
|
|
|
|
|
+ tts_stream = gTTS(text=msg, lang='en')
|
|
|
with open(cache_fname, 'w') as f:
|
|
with open(cache_fname, 'w') as f:
|
|
|
tts_stream.write_to_fp(f)
|
|
tts_stream.write_to_fp(f)
|
|
|
|
|
|
|
|
_play(cache_fname, True)
|
|
_play(cache_fname, True)
|
|
|
|
|
|
|
|
- def success(self):
|
|
|
|
|
|
|
+ def success(self, *_):
|
|
|
_play_clip(Clips.SUCCESS)
|
|
_play_clip(Clips.SUCCESS)
|
|
|
|
|
|
|
|
def failure(self, *_):
|
|
def failure(self, *_):
|
|
|
_play_clip(Clips.FAILURE)
|
|
_play_clip(Clips.FAILURE)
|
|
|
|
|
|
|
|
- def cancelled(self):
|
|
|
|
|
- self.tts('cancelled')
|
|
|
|
|
|
|
+ def cancelled(self, msg):
|
|
|
|
|
+ self.tts(msg)
|