TTS: Cache the voices list

This commit is contained in:
Gonzalo Odiard 2014-11-09 22:37:58 -03:00 committed by Martin Abente Lahaye
parent 57bd0890f5
commit 31d8de55a7

View File

@ -229,6 +229,7 @@ class _GstSpeechPlayer(GObject.GObject):
def __init__(self): def __init__(self):
GObject.GObject.__init__(self) GObject.GObject.__init__(self)
self._pipeline = None self._pipeline = None
self._all_voices = None
def restart_sound_device(self): def restart_sound_device(self):
if self._pipeline is None: if self._pipeline is None:
@ -290,14 +291,17 @@ class _GstSpeechPlayer(GObject.GObject):
self.restart_sound_device() self.restart_sound_device()
def get_all_voices(self): def get_all_voices(self):
all_voices = {} if self._all_voices is not None:
return self._all_voices
self._all_voices = {}
for voice in Gst.ElementFactory.make('espeak', None).props.voices: for voice in Gst.ElementFactory.make('espeak', None).props.voices:
name, language, dialect = voice name, language, dialect = voice
if dialect != 'none': if dialect != 'none':
all_voices[language + '_' + dialect] = name self._all_voices[language + '_' + dialect] = name
else: else:
all_voices[language] = name self._all_voices[language] = name
return all_voices return self._all_voices
def get_default_voice(self): def get_default_voice(self):
"""Try to figure out the default voice, from the current locale ($LANG) """Try to figure out the default voice, from the current locale ($LANG)