diff options
author | James Simmons <nicestep@gmail.com> | 2016-01-24 21:09:03 (GMT) |
---|---|---|
committer | James Simmons <nicestep@gmail.com> | 2016-01-24 21:09:03 (GMT) |
commit | b5ceb9f4469e281da95950cf6e6bc3d2a6f9e0e2 (patch) | |
tree | 7a96d217acd5cc66ab6e72b5e3ca2e2fce81ae51 | |
parent | f7fbb36e0d81f14509a96ec9d6e52a0d179017bb (diff) |
modified: gst_simple_example.py
modified: speech.py
Fix code to use Gst instead of gst.
modified: ReadEtextsTTS.py
modified: gst_simple_example.py
modified: speech.py
-rwxr-xr-x | Adding_TTS_gtk3/ReadEtextsTTS.py | 10 | ||||
-rwxr-xr-x | Adding_TTS_gtk3/gst_simple_example.py | 15 | ||||
-rw-r--r-- | Adding_TTS_gtk3/speech.py | 38 |
3 files changed, 36 insertions, 27 deletions
diff --git a/Adding_TTS_gtk3/ReadEtextsTTS.py b/Adding_TTS_gtk3/ReadEtextsTTS.py index 161f8c1..47bfc66 100755 --- a/Adding_TTS_gtk3/ReadEtextsTTS.py +++ b/Adding_TTS_gtk3/ReadEtextsTTS.py @@ -22,19 +22,21 @@ import sys import os import zipfile +import gi +gi.require_version('Gtk', '3.0') from gi.repository import Gtk from gi.repository import Gdk import getopt from gi.repository import Pango -from gi.repository import GObject -import time import speech speech_supported = True try: - import gst - gst.element_factory_make('espeak') + gi.require_version('Gst', '1.0') + from gi.repository import Gst + Gst.init(None) + Gst.ElementFactory.make('espeak') print 'speech supported!' except Exception, e: speech_supported = False diff --git a/Adding_TTS_gtk3/gst_simple_example.py b/Adding_TTS_gtk3/gst_simple_example.py index 3962777..469c2a7 100755 --- a/Adding_TTS_gtk3/gst_simple_example.py +++ b/Adding_TTS_gtk3/gst_simple_example.py @@ -1,3 +1,4 @@ +#!/usr/bin/python # # <one line to give the program's name and a brief idea of what it does.> # Copyright (C) <YEAR> <NAME> @@ -17,20 +18,24 @@ # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # +import gi +gi.require_version('Gtk', '3.0') from gi.repository import Gtk -import gst +gi.require_version('Gst', '1.0') +from gi.repository import Gst +Gst.init(None) def gstmessage_cb(bus, message, pipe): - if message.type in (gst.MESSAGE_EOS, gst.MESSAGE_ERROR): - pipe.set_state(gst.STATE_NULL) + if message.type in (Gst.MessageType.EOS, Gst.MessageType.ERROR): + pipe.set_state(Gst.State.NULL) pipeline = 'espeak text="Hello, World!" ! autoaudiosink' -pipe = gst.parse_launch(pipeline) +pipe = Gst.parse_launch(pipeline) bus = pipe.get_bus() bus.add_signal_watch() bus.connect('message', gstmessage_cb, pipe) -pipe.set_state(gst.STATE_PLAYING) +pipe.set_state(Gst.State.PLAYING) Gtk.main() 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', '_', '[', '{', ']', '}', '|', '<',\ '>', '*', '+', '/', '\\' ] |