diff options
Diffstat (limited to 'Adding_TTS_gtk3/speech.py')
-rw-r--r-- | Adding_TTS_gtk3/speech.py | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/Adding_TTS_gtk3/speech.py b/Adding_TTS_gtk3/speech.py index cdab7d2..c56a43c 100644 --- a/Adding_TTS_gtk3/speech.py +++ b/Adding_TTS_gtk3/speech.py @@ -1,6 +1,6 @@ # speech.py -# Copyright (C) 2010 Aleksey Lim and James D. Simmons +# Copyright (C) 2016 Aleksey Lim and James D. Simmons # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -16,8 +16,10 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -import gst - +import gi +gi.require_version('Gst', '1.0') +from gi.repository import Gst +Gst.init(None) voice = 'default' pitch = 0 @@ -26,21 +28,22 @@ highlight_cb = None def _create_pipe(): pipeline = 'espeak name=source ! autoaudiosink' - pipe = gst.parse_launch(pipeline) + pipe = Gst.parse_launch(pipeline) def stop_cb(bus, message): - pipe.set_state(gst.STATE_NULL) + pipe.set_state(Gst.State.NULL) def mark_cb(bus, message): - if message.structure.get_name() == 'espeak-mark': - mark = message.structure['mark'] + if message.get_structure().get_name() == 'espeak-mark': + mark = message.get_structure().get_value('mark') highlight_cb(int(mark)) bus = pipe.get_bus() bus.add_signal_watch() bus.connect('message::eos', stop_cb) bus.connect('message::error', stop_cb) - bus.connect('message::element', mark_cb) + bus.enable_sync_message_emission() + bus.connect('sync-message::element', mark_cb) return (pipe.get_by_name('source'), pipe) @@ -49,7 +52,7 @@ def _speech(source, pipe, words): source.props.rate = rate source.props.voice = voice source.props.text = words; - pipe.set_state(gst.STATE_PLAYING) + pipe.set_state(Gst.State.PLAYING) info_source, info_pipe = _create_pipe() play_source, play_pipe = _create_pipe() @@ -68,22 +71,22 @@ def play(words): _speech(play_source, play_pipe, words) def is_stopped(): - for i in play_pipe.get_state(): - if isinstance(i, gst.State) and i == gst.STATE_NULL: - return True + for i in play_pipe.get_state(Gst.CLOCK_TIME_NONE): + if isinstance(i, Gst.State) and i == Gst.State.NULL: + return True return False def stop(): - play_pipe.set_state(gst.STATE_NULL) + play_pipe.set_state(Gst.State.NULL) def is_paused(): - for i in play_pipe.get_state(): - if isinstance(i, gst.State) and i == gst.STATE_PAUSED: - return True + for i in play_pipe.get_state(Gst.CLOCK_TIME_NONE): + if isinstance(i, Gst.State) and i == Gst.State.PAUSED: + return True return False def pause(): - play_pipe.set_state(gst.STATE_PAUSED) + play_pipe.set_state(Gst.State.PAUSED) def rate_up(): global rate @@ -106,7 +109,6 @@ def prepare_highlighting(label_text): j = 0 word_begin = 0 word_end = 0 - current_word = 0 word_tuples = [] omitted = [' ', '\n', u'\r', '_', '[', '{', ']', '}', '|', '<',\ '>', '*', '+', '/', '\\' ] |