Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, *args, **kwargs):
plugin.TTSPlugin.__init__(self, *args, **kwargs)
try:
orig_language = self.profile['language']
except:
orig_language = 'en-US'
language = orig_language.lower()
if language not in gtts.gTTS.LANGUAGES:
language = language.split('-')[0]
if language not in gtts.gTTS.LANGUAGES:
raise ValueError("Language '%s' ('%s') not supported" %
(language, orig_language))
self.language = language
def languages():
"""Sorted pretty printed string of supported languages"""
return ", ".join(sorted("{}: '{}'".format(gTTS.LANGUAGES[k], k) for k in gTTS.LANGUAGES))
def _get_languages(self):
voices = gtts.gTTS.LANGUAGES.keys()
langs = {}
for voice in voices:
lang = voice[:2]
langs.setdefault(lang, {'default': voice, 'voices': {}})
langs[lang]['voices'][voice] = {}
return langs
def send(self, jid, text, lang=None):
if not (lang and lang in gTTS.LANGUAGES):
lang = "en"
try:
file_path = self.tts_record(text, lang)
self.send_by_path(jid, file_path)
except Exception as e:
logging.exception(e)
self._on_error(jid)