googletts.py 887 B

123456789101112131415161718192021222324252627282930
  1. import logging
  2. from core import AudioPlayer
  3. from tts import TTS
  4. logging.basicConfig()
  5. logger = logging.getLogger("jarvis")
  6. class Googletts(TTS):
  7. TTS_LANGUAGES_DEFAULT = 'fr'
  8. TTS_URL = "http://translate.google.com/translate_tts"
  9. TTS_CONTENT_TYPE = "audio/mpeg"
  10. TTS_TIMEOUT_SEC = 30
  11. def __init__(self):
  12. TTS.__init__(self)
  13. def say(self, words=None, language=TTS_LANGUAGES_DEFAULT, cache=True):
  14. self.say_generic(cache, language, words, self.get_audio_googletts, AudioPlayer.PLAYER_MP3, 25000)
  15. def get_audio_googletts(self, language, words, file_path, cache):
  16. payload = {
  17. "q": words,
  18. "tl": language,
  19. "ie": "UTF-8",
  20. "total": "1",
  21. "client": "tw-ob"
  22. }
  23. return self.get_audio(file_path, cache, payload, self.TTS_URL, self.TTS_CONTENT_TYPE, self.TTS_TIMEOUT_SEC)