From fc4d629b50a1303a7e79fede0b02d8ec8c0ce793 Mon Sep 17 00:00:00 2001 From: Gonzalo Odiard Date: Tue, 12 May 2015 13:10:17 -0300 Subject: [PATCH] TTS in the toolkit need initialize gstreamer - Fixes #4851 If is not initialized, the check for the espeak plugin will fail. This patch also check for the espeak plugin at the beginnig avoiding check every time the function enabled() is called. --- src/sugar3/speech.py | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/src/sugar3/speech.py b/src/sugar3/speech.py index a88cdf9d..10777eee 100644 --- a/src/sugar3/speech.py +++ b/src/sugar3/speech.py @@ -18,7 +18,6 @@ import os import logging from gettext import gettext as _ -from gi.repository.GLib import GError from gi.repository import Gio from gi.repository import Gtk from gi.repository import Gdk @@ -27,7 +26,10 @@ from gi.repository import GObject _HAS_GST = True try: from gi.repository import Gst + Gst.init(None) + Gst.parse_launch('espeak') except: + logging.error('Gst or the espeak plugin is not installed in the system.') _HAS_GST = False from sugar3 import power @@ -116,24 +118,6 @@ translated_espeak_voices = { } -def _has_espeak_module(): - try: - Gst.parse_launch('espeak') - except GError: - logging.error('The speech plugin is not installed in the system.') - return False - return True - - -def _check_modules(): - if not _HAS_GST: - logging.error('GST is not installed in the system.') - return False - if not _has_espeak_module(): - return False - return True - - class SpeechManager(GObject.GObject): __gtype_name__ = 'SpeechManager' @@ -169,7 +153,7 @@ class SpeechManager(GObject.GObject): self.restore() def enabled(self): - return _check_modules() + return _HAS_GST def _update_state(self, player, signal): self._is_playing = (signal == 'play') @@ -277,7 +261,6 @@ class _GstSpeechPlayer(GObject.GObject): } def __init__(self): - Gst.init(None) GObject.GObject.__init__(self) self._pipeline = None self._all_voices = None