Coverage Report - orca.speechserver

ModuleCoverage %
orca.speechserver
78%
1
# Orca
2
#
3
# Copyright 2005-2006 Sun Microsystems Inc.
4
#
5
# This library is free software; you can redistribute it and/or
6
# modify it under the terms of the GNU Library General Public
7
# License as published by the Free Software Foundation; either
8
# version 2 of the License, or (at your option) any later version.
9
#
10
# This library is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
# Library General Public License for more details.
14
#
15
# You should have received a copy of the GNU Library General Public
16
# License along with this library; if not, write to the
17
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
# Boston, MA 02111-1307, USA.
19
20
"""Provides an abtract class for working with speech servers.
21
22
A speech server (class SpeechServer) provides the ability to tell the
23
machine to speak.  Each speech server provides a set of known
24
voices (identified by name) which can be combined with various
25 1
attributes to create aural style sheets."""
26
27 1
__id__        = "$Id: speechserver.py 1552 2006-10-13 23:39:04Z wwalker $"
28 1
__version__   = "$Revision: 1552 $"
29 1
__date__      = "$Date: 2006-10-13 16:39:04 -0700 (Fri, 13 Oct 2006) $"
30 1
__copyright__ = "Copyright (c) 2005-2006 Sun Microsystems Inc."
31 1
__license__   = "LGPL"
32
33 1
import logging
34 1
log = logging.getLogger("speech")
35
36 1
import debug
37
38 2
class VoiceFamily(dict):
39
    """Holds the family description for a voice."""
40
41 1
    NAME   = "name"
42 1
    GENDER = "gender"
43 1
    LOCALE = "locale"
44
45 1
    MALE   = "male"
46 1
    FEMALE = "female"
47
48 1
    settings = {
49
        NAME   : None,
50
        GENDER : None,
51
        LOCALE : None
52
    }
53
54 1
    def __init__(self, props):
55
        """Create and initialize VoiceFamily."""
56 0
        self.update(VoiceFamily.settings)
57 0
        if props:
58 0
            self.update(props)
59
60 2
class SayAllContext:
61
62 1
    PROGRESS    = 0
63 1
    INTERRUPTED = 1
64 1
    COMPLETED   = 2
65
66 1
    def __init__(self, obj, utterance, startOffset=-1, endOffset=-1):
67
        """Creates a new SayAllContext that will be passed to the
68
        SayAll callback handler for progress updates on speech.
69
        If the object does not have an accessible text specialization,
70
        then startOffset and endOffset parameters are meaningless.
71
        If the object does have an accessible text specialization,
72
        then values >= 0 for startOffset and endOffset indicate
73
        where in the text the utterance has come from.
74
75
        Arguments:
76
        -obj:         the Accessible being spoken
77
        -utterance:   the actual utterance being spoken
78
        -startOffset: the start offset of the Accessible's text
79
        -endOffset:   the end offset of the Accessible's text
80
        """
81 0
        self.obj           = obj
82 0
        self.utterance     = utterance
83 0
        self.startOffset   = startOffset
84 0
        self.currentOffset = startOffset
85 0
        self.endOffset     = endOffset
86
87 2
class SpeechServer:
88
89
    """Provides speech server abstraction."""
90
91 1
    def getFactoryName():
92
        """Returns a localized name describing this factory."""
93
        pass
94
95 1
    getFactoryName = staticmethod(getFactoryName)
96
97 1
    def getSpeechServers():
98
        """Gets available speech servers as a list.  The caller
99
        is responsible for calling the shutdown() method of each
100
        speech server returned.
101
        """
102
        pass
103
104 1
    getSpeechServers = staticmethod(getSpeechServers)
105
106 1
    def getSpeechServer(info):
107
        """Gets a given SpeechServer based upon the info.
108
        See SpeechServer.getInfo() for more info.
109
        """
110
        pass
111
112 1
    getSpeechServer = staticmethod(getSpeechServer)
113
114 1
    def shutdownActiveServers():
115
        """Cleans up and shuts down this factory.
116
        """
117
        pass
118
119 1
    shutdownActiveServers = staticmethod(shutdownActiveServers)
120
121 1
    def __init__(self):
122 1
        pass
123
124 1
    def getInfo(self):
125
        """Returns [name, id]
126
        """
127
        pass
128
129 1
    def getVoiceFamilies(self):
130
        """Returns a list of VoiceFamily instances representing all
131
        voice families known by the speech server."""
132
        pass
133
134 1
    def queueText(self, text="", acss=None):
135
        """Adds the text to the queue.
136
137
        Arguments:
138
        - text: text to be spoken
139
        - acss: acss.ACSS instance; if None,
140
                the default voice settings will be used.
141
                Otherwise, the acss settings will be
142
                used to augment/override the default
143
                voice settings.
144
145
        Output is produced by the next call to speak.
146
        """
147
        pass
148
149 1
    def queueTone(self, pitch=440, duration=50):
150
        """Adds a tone to the queue.
151
152
        Output is produced by the next call to speak.
153
        """
154
        pass
155
156 1
    def queueSilence(self, duration=50):
157
        """Adds silence to the queue.
158
159
        Output is produced by the next call to speak.
160
        """
161
        pass
162
163 1
    def speakCharacter(self, character, acss=None):
164
        """Speaks a single character immediately.
165
166
        Arguments:
167
        - character: text to be spoken
168
        - acss:      acss.ACSS instance; if None,
169
                     the default voice settings will be used.
170
                     Otherwise, the acss settings will be
171
                     used to augment/override the default
172
                     voice settings.
173
        """
174
        pass
175
176 1
    def speakUtterances(self, list, acss=None, interrupt=True):
177
        """Speaks the given list of utterances immediately.
178
179
        Arguments:
180
        - list:      list of strings to be spoken
181
        - acss:      acss.ACSS instance; if None,
182
                     the default voice settings will be used.
183
                     Otherwise, the acss settings will be
184
                     used to augment/override the default
185
                     voice settings.
186
        - interrupt: if True, stop any speech currently in progress.
187
        """
188
        pass
189
190 1
    def speak(self, text=None, acss=None, interrupt=True):
191
        """Speaks all queued text immediately.  If text is not None,
192
        it is added to the queue before speaking.
193
194
        Arguments:
195
        - text:      optional text to add to the queue before speaking
196
        - acss:      acss.ACSS instance; if None,
197
                     the default voice settings will be used.
198
                     Otherwise, the acss settings will be
199
                     used to augment/override the default
200
                     voice settings.
201
        - interrupt: if True, stops any speech in progress before
202
                     speaking the text
203
        """
204
        pass
205
206 1
    def isSpeaking(self):
207
	""""Returns True if the system is currently speaking."""
208 0
	return False
209
210 1
    def sayAll(self, utteranceIterator, progressCallback):
211
        """Iterates through the given utteranceIterator, speaking
212
        each utterance one at a time.  Subclasses may postpone
213
        getting a new element until the current element has been
214
        spoken.
215
216
        Arguments:
217
        - utteranceIterator: iterator/generator whose next() function
218
                             returns a [SayAllContext, acss] tuple
219
        - progressCallback:  called as speech progress is made - has a
220
                             signature of (SayAllContext, type), where
221
                             type is one of PROGRESS, INTERRUPTED, or
222
                             COMPLETED.
223
        """
224 0
        for [context, acss] in utteranceIterator:
225 0
            debug.println(debug.LEVEL_INFO,
226 0
                          "SPEECH OUTPUT: '" + context.utterance + "'")
227 0
            log.info("'%s'" % context.utterance)
228 0
            self.speak(context.utterance, acss)
229
230 1
    def increaseSpeechRate(self, step=5):
231
        """Increases the speech rate.
232
        """
233
        pass
234
235 1
    def decreaseSpeechRate(self, step=5):
236
        """Decreases the speech rate.
237
        """
238
        pass
239
240 1
    def increaseSpeechPitch(self, step=0.5):
241
        """Increases the speech pitch.
242
        """
243
        pass
244
245 1
    def decreaseSpeechPitch(self, step=0.5):
246
        """Decreases the speech pitch.
247
        """
248
        pass
249
250 1
    def stop(self):
251
        """Stops ongoing speech and flushes the queue."""
252
        pass
253
254 1
    def shutdown(self):
255
        """Shuts down the speech engine."""
256
        pass
257
258 1
    def reset(self, text=None, acss=None):
259
        """Resets the speech engine."""
260
        pass