13 | 13 |
# along with this program; if not, write to the Free Software
|
14 | 14 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
15 | 15 |
|
|
16 |
from gi.repository import Gst
|
16 | 17 |
import logging
|
17 | |
import pygst
|
18 | |
pygst.require("0.10")
|
19 | |
from gi.repository import Gst
|
20 | 18 |
|
21 | 19 |
import speech
|
22 | 20 |
|
23 | |
_logger = logging.getLogger('read-etexts-activity')
|
|
21 |
_logger = logging.getLogger('read-activity')
|
|
22 |
|
|
23 |
|
|
24 |
def get_all_voices():
|
|
25 |
all_voices = {}
|
|
26 |
for voice in Gst.ElementFactory.make('espeak', None).props.voices:
|
|
27 |
name, language, dialect = voice
|
|
28 |
if dialect != 'none':
|
|
29 |
all_voices[language + '_' + dialect] = name
|
|
30 |
else:
|
|
31 |
all_voices[language] = name
|
|
32 |
return all_voices
|
24 | 33 |
|
25 | 34 |
|
26 | 35 |
def _message_cb(bus, message, pipe):
|
27 | |
logging.error('gstreamer message %s', message)
|
28 | |
if message is None:
|
29 | |
return
|
30 | |
if message.type == Gst.Message.EOS:
|
|
36 |
if message.type == Gst.MessageType.EOS:
|
31 | 37 |
pipe.set_state(Gst.State.NULL)
|
32 | 38 |
if speech.end_text_cb != None:
|
33 | 39 |
speech.end_text_cb()
|
34 | |
if message.type == Gst.Message.ERROR:
|
|
40 |
if message.type == Gst.MessageType.ERROR:
|
35 | 41 |
pipe.set_state(Gst.State.NULL)
|
36 | 42 |
if pipe is play_speaker[1]:
|
37 | |
if speech.reset_cb is not None:
|
38 | |
speech.reset_cb()
|
39 | |
if speech.reset_buttons_cb is not None:
|
40 | |
speech.reset_buttons_cb()
|
41 | |
elif message.type == Gst.Message.ELEMENT and \
|
|
43 |
speech.reset_cb()
|
|
44 |
elif message.type == Gst.MessageType.ELEMENT and \
|
42 | 45 |
message.structure.get_name() == 'espeak-mark':
|
43 | 46 |
mark = message.structure['mark']
|
44 | 47 |
speech.highlight_cb(int(mark))
|
45 | 48 |
|
46 | 49 |
|
47 | 50 |
def _create_pipe():
|
48 | |
pipe = Gst.Pipeline()
|
49 | |
pipe.set_name('pipeline')
|
50 | |
|
51 | |
source = Gst.ElementFactory.make('espeak', 'source')
|
52 | |
pipe.add(source)
|
53 | |
|
54 | |
sink = Gst.ElementFactory.make('autoaudiosink', 'sink')
|
55 | |
pipe.add(sink)
|
56 | |
source.link(sink)
|
|
51 |
pipe = Gst.parse_launch('espeak name=espeak ! autoaudiosink')
|
|
52 |
source = pipe.get_by_name('espeak')
|
57 | 53 |
|
58 | 54 |
bus = pipe.get_bus()
|
59 | 55 |
bus.add_signal_watch()
|
60 | |
logging.error('before adding message callback')
|
61 | 56 |
bus.connect('message', _message_cb, pipe)
|
62 | |
logging.error('ater adding message callback')
|
63 | 57 |
|
64 | 58 |
return (source, pipe)
|
65 | 59 |
|
|
72 | 66 |
speaker[1].set_state(Gst.State.NULL)
|
73 | 67 |
speaker[1].set_state(Gst.State.PLAYING)
|
74 | 68 |
|
75 | |
Gst.init_check(None)
|
|
69 |
|
76 | 70 |
info_speaker = _create_pipe()
|
77 | 71 |
play_speaker = _create_pipe()
|
78 | 72 |
play_speaker[0].props.track = 2
|
|
90 | 84 |
_speech(play_speaker, words)
|
91 | 85 |
|
92 | 86 |
|
|
87 |
def pause():
|
|
88 |
play_speaker[1].set_state(Gst.State.PAUSED)
|
|
89 |
|
|
90 |
|
|
91 |
def continue_play():
|
|
92 |
play_speaker[1].set_state(Gst.State.PLAYING)
|
|
93 |
|
|
94 |
|
93 | 95 |
def is_stopped():
|
94 | |
for i in play_speaker[1].get_state(1):
|
|
96 |
for i in play_speaker[1].get_state():
|
95 | 97 |
if isinstance(i, Gst.State) and i == Gst.State.NULL:
|
96 | 98 |
return True
|
97 | 99 |
return False
|
98 | 100 |
|
99 | 101 |
|
100 | |
def pause():
|
101 | |
play_speaker[1].set_state(Gst.State.NULL)
|
102 | |
|
103 | |
|
104 | 102 |
def stop():
|
105 | 103 |
play_speaker[1].set_state(Gst.State.NULL)
|
106 | |
play_speaker[0].props.text = ''
|
107 | |
if speech.reset_cb is not None:
|
108 | |
speech.reset_cb()
|
109 | |
if speech.reset_buttons_cb is not None:
|
110 | |
speech.reset_buttons_cb()
|