Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update all copyright headers

  • Loading branch information...
commit f9ef51cd4e1535c09941bf30571fd1fd8ceb316d 1 parent 926db68
@parente authored
View
6 pyttsx/__init__.py
@@ -1,7 +1,7 @@
'''
pyttsx package.
-Copyright (c) 2009 Peter Parente
+Copyright (c) 2009, 2013 Peter Parente
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -24,8 +24,8 @@ def init(driverName=None, debug=False):
'''
Constructs a new TTS engine instance or reuses the existing instance for
the driver name.
-
- @param driverName: Name of the platform specific driver to use. If
+
+ @param driverName: Name of the platform specific driver to use. If
None, selects the default driver for the operating system.
@type: str
@param debug: Debugging output enabled or not
View
34 pyttsx/driver.py
@@ -1,7 +1,7 @@
'''
Proxy for drivers.
-Copyright (c) 2009 Peter Parente
+Copyright (c) 2009, 2013 Peter Parente
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -22,14 +22,14 @@
class DriverProxy(object):
'''
Proxy to a driver implementation.
-
+
@ivar _module: Module containing the driver implementation
@type _module: module
@ivar _engine: Reference to the engine that owns the driver
@type _engine: L{engine.Engine}
@ivar _queue: Queue of commands outstanding for the driver
@type _queue: list
- @ivar _busy: True when the driver is busy processing a command, False when
+ @ivar _busy: True when the driver is busy processing a command, False when
not
@type _busy: bool
@ivar _name: Name associated with the current utterance
@@ -42,7 +42,7 @@ class DriverProxy(object):
def __init__(self, engine, driverName, debug):
'''
Constructor.
-
+
@param engine: Reference to the engine that owns the driver
@type engine: L{engine.Engine}
@param driverName: Name of the driver module to use under drivers/ or
@@ -71,7 +71,7 @@ def __init__(self, engine, driverName, debug):
self._name = None
self._iterator = None
self._debug = debug
-
+
def __del__(self):
try:
self._driver.destroy()
@@ -81,7 +81,7 @@ def __del__(self):
def _push(self, mtd, args, name=None):
'''
Adds a command to the queue.
-
+
@param mtd: Method to invoke to process the command
@type mtd: method
@param args: Arguments to apply when invoking the method
@@ -109,7 +109,7 @@ def _pump(self):
def notify(self, topic, **kwargs):
'''
Sends a notification to the engine from the driver.
-
+
@param topic: Notification topic
@type topic: str
@param kwargs: Arbitrary keyword arguments
@@ -121,7 +121,7 @@ def notify(self, topic, **kwargs):
def setBusy(self, busy):
'''
Called by the driver to indicate it is busy.
-
+
@param busy: True when busy, false when idle
@type busy: bool
'''
@@ -135,11 +135,11 @@ def isBusy(self):
@rtype: bool
'''
return self._busy
-
+
def say(self, text, name):
'''
Called by the engine to push a say command onto the queue.
-
+
@param text: Text to speak
@type text: unicode
@param name: Name to associate with the utterance
@@ -165,7 +165,7 @@ def stop(self):
def getProperty(self, name):
'''
Called by the engine to get a driver property value.
-
+
@param name: Name of the property
@type name: str
@return: Property value
@@ -176,22 +176,22 @@ def getProperty(self, name):
def setProperty(self, name, value):
'''
Called by the engine to set a driver property value.
-
+
@param name: Name of the property
@type name: str
@param value: Property value
@type value: object
'''
self._push(self._driver.setProperty, (name, value))
-
+
def runAndWait(self):
'''
- Called by the engine to start an event loop, process all commands in
+ Called by the engine to start an event loop, process all commands in
the queue at the start of the loop, and then exit the loop.
'''
self._push(self._engine.endLoop, tuple())
self._driver.startLoop()
-
+
def startLoop(self, useDriverLoop):
'''
Called by the engine to start an event loop.
@@ -200,7 +200,7 @@ def startLoop(self, useDriverLoop):
self._driver.startLoop()
else:
self._iterator = self._driver.iterate()
-
+
def endLoop(self, useDriverLoop):
'''
Called by the engine to stop an event loop.
@@ -212,7 +212,7 @@ def endLoop(self, useDriverLoop):
else:
self._iterator = None
self.setBusy(True)
-
+
def iterate(self):
'''
Called by the engine to iterate driver commands and notifications from
View
2  pyttsx/drivers/__init__.py
@@ -1,7 +1,7 @@
'''
Speech driver implementations.
-Copyright (c) 2009 Peter Parente
+Copyright (c) 2009, 2013 Peter Parente
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
View
52 pyttsx/drivers/dummy.py
@@ -2,7 +2,7 @@
Dummy driver that produces no output but gives all expected callbacks. Useful
for testing and as a model for real drivers.
-Copyright (c) 2009 Peter Parente
+Copyright (c) 2009, 2013 Peter Parente
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -21,9 +21,9 @@
def buildDriver(proxy):
'''
- Builds a new instance of a driver and returns it for use by the driver
+ Builds a new instance of a driver and returns it for use by the driver
proxy.
-
+
@param proxy: Proxy creating the driver
@type proxy: L{driver.DriverProxy}
'''
@@ -31,9 +31,9 @@ def buildDriver(proxy):
class DummyDriver(object):
'''
- Dummy speech engine implementation. Documents the interface, notifications,
+ Dummy speech engine implementation. Documents the interface, notifications,
properties, and sequencing responsibilities of a driver implementation.
-
+
@ivar _proxy: Driver proxy that manages this instance
@type _proxy: L{driver.DriverProxy}
@ivar _config: Dummy configuration
@@ -46,11 +46,11 @@ def __init__(self, proxy):
Constructs the driver.
@param proxy: Proxy creating the driver
- @type proxy: L{driver.DriverProxy}
+ @type proxy: L{driver.DriverProxy}
'''
self._proxy = proxy
self._looping = False
- # hold config values as if we had a real tts implementation that
+ # hold config values as if we had a real tts implementation that
# supported them
voices = [
Voice('dummy.voice1', 'John Doe', ['en-US', 'en-GB'], 'male', 'adult'),
@@ -58,12 +58,12 @@ def __init__(self, proxy):
Voice('dummy.voice3', 'Jimmy Doe', ['en-US', 'en-GB'], 'male', 10)
]
self._config = {
- 'rate' : 200,
- 'volume' : 1.0,
+ 'rate' : 200,
+ 'volume' : 1.0,
'voice' : voices[0],
'voices' : voices
}
-
+
def destroy(self):
'''
Optional method that will be called when the driver proxy is being
@@ -74,9 +74,9 @@ def destroy(self):
def startLoop(self):
'''
- Starts a blocking run loop in which driver callbacks are properly
+ Starts a blocking run loop in which driver callbacks are properly
invoked.
-
+
@precondition: There was no previous successful call to L{startLoop}
without an intervening call to L{stopLoop}.
'''
@@ -90,13 +90,13 @@ def startLoop(self):
def endLoop(self):
'''
- Stops a previously started run loop.
-
+ Stops a previously started run loop.
+
@precondition: A previous call to L{startLoop} suceeded and there was
no intervening call to L{endLoop}.
'''
self._looping = False
-
+
def iterate(self):
'''
Iterates from within an external run loop.
@@ -106,25 +106,25 @@ def iterate(self):
def say(self, text):
'''
- Speaks the given text. Generates the following notifications during
+ Speaks the given text. Generates the following notifications during
output:
-
+
started-utterance: When speech output has started
started-word: When a word is about to be spoken. Includes the character
"location" of the start of the word in the original utterance text
and the "length" of the word in characters.
finished-utterance: When speech output has finished. Includes a flag
indicating if the entire utterance was "completed" or not.
-
+
The proxy automatically adds any "name" associated with the utterance
to the notifications on behalf of the driver.
-
+
When starting to output an utterance, the driver must inform its proxy
that it is busy by invoking L{driver.DriverProxy.setBusy} with a flag
of True. When the utterance completes or is interrupted, the driver
- inform the proxy that it is no longer busy by invoking
+ inform the proxy that it is no longer busy by invoking
L{driver.DriverProxy.setBusy} with a flag of False.
-
+
@param text: Unicode text to speak
@type text: unicode
'''
@@ -148,17 +148,17 @@ def stop(self):
proxy.
'''
pass
-
+
def getProperty(self, name):
'''
Gets a property value of the speech engine. The suppoted properties
and their values are:
-
+
voices: List of L{voice.Voice} objects supported by the driver
voice: String ID of the current voice
rate: Integer speech rate in words per minute
volume: Floating point volume of speech in the range [0.0, 1.0]
-
+
@param name: Property name
@type name: str
@raise KeyError: When the property name is unknown
@@ -167,13 +167,13 @@ def getProperty(self, name):
return self._config[name]
except KeyError:
raise KeyError('unknown property %s' % name)
-
+
def setProperty(self, name, value):
'''
Sets one of the supported property values of the speech engine listed
above. If a value is invalid, attempts to clip it / coerce so it is
valid before giving up and firing an exception.
-
+
@param name: Property name
@type name: str
@param value: Property value
View
22 pyttsx/drivers/espeak.py
@@ -1,7 +1,7 @@
'''
espeak driver.
-Copyright (c) 2009 Peter Parente
+Copyright (c) 2009, 2013 Peter Parente
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -28,7 +28,7 @@ class EspeakDriver(object):
_defaultVoice = ''
def __init__(self, proxy):
if not EspeakDriver._moduleInitialized:
- # espeak cannot initialize more than once per process and has
+ # espeak cannot initialize more than once per process and has
# issues when terminating from python (assert error on close)
# so just keep it alive and init once
rate = _espeak.Initialize(_espeak.AUDIO_OUTPUT_PLAYBACK, 1000)
@@ -52,11 +52,11 @@ def say(self, text):
self._proxy.setBusy(True)
self._proxy.notify('started-utterance')
_espeak.Synth(text, flags=_espeak.ENDPAUSE)
-
+
def stop(self):
if _espeak.IsPlaying():
self._stopping = True
-
+
def getProperty(self, name):
if name == 'voices':
voices = []
@@ -79,7 +79,7 @@ def getProperty(self, name):
return _espeak.GetParameter(_espeak.VOLUME)/100.0
else:
raise KeyError('unknown property %s' % name)
-
+
def setProperty(self, name, value):
if name == 'voice':
if value is None: return
@@ -99,7 +99,7 @@ def setProperty(self, name, value):
raise ValueError(str(e))
else:
raise KeyError('unknown property %s' % name)
-
+
def startLoop(self):
first = True
self._looping = True
@@ -116,10 +116,10 @@ def startLoop(self):
self._proxy.notify('finished-utterance', completed=False)
self._proxy.setBusy(False)
time.sleep(0.01)
-
+
def endLoop(self):
self._looping = False
-
+
def iterate(self):
self._proxy.setBusy(False)
while 1:
@@ -131,7 +131,7 @@ def iterate(self):
self._proxy.notify('finished-utterance', completed=False)
self._proxy.setBusy(False)
yield
-
+
def _onSynth(self, wav, numsamples, events):
i = 0
while True:
@@ -139,8 +139,8 @@ def _onSynth(self, wav, numsamples, events):
if event.type == _espeak.EVENT_LIST_TERMINATED:
break
if event.type == _espeak.EVENT_WORD:
- self._proxy.notify('started-word',
- location=event.text_position-1,
+ self._proxy.notify('started-word',
+ location=event.text_position-1,
length=event.length)
elif event.type == _espeak.EVENT_MSG_TERMINATED:
self._proxy.notify('finished-utterance', completed=True)
View
24 pyttsx/drivers/nsss.py
@@ -1,7 +1,7 @@
'''
NSSpeechSynthesizer driver.
-Copyright (c) 2009 Peter Parente
+Copyright (c) 2009, 2013 Peter Parente
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -38,18 +38,18 @@ def initWithProxy(self, proxy):
def destroy(self):
self._tts.setDelegate_(None)
del self._tts
-
+
def onPumpFirst_(self, timer):
self._proxy.setBusy(False)
-
+
def startLoop(self):
NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(
0.0, self, 'onPumpFirst:', None, False)
AppHelper.runConsoleEventLoop()
-
+
def endLoop(self):
AppHelper.stopEventLoop()
-
+
def iterate(self):
self._proxy.setBusy(False)
yield
@@ -59,21 +59,21 @@ def say(self, text):
self._completed = True
self._proxy.notify('started-utterance')
self._tts.startSpeakingString_(unicode(text))
-
+
def stop(self):
if self._proxy.isBusy():
self._completed = False
self._tts.stopSpeaking()
-
+
def _toVoice(self, attr):
return Voice(attr['VoiceIdentifier'], attr['VoiceName'],
[attr['VoiceLanguage']], attr['VoiceGender'],
attr['VoiceAge'])
-
+
def getProperty(self, name):
if name == 'voices':
return [self._toVoice(NSSpeechSynthesizer.attributesForVoice_(v))
- for v in list(NSSpeechSynthesizer.availableVoices())]
+ for v in list(NSSpeechSynthesizer.availableVoices())]
elif name == 'voice':
return self._tts.voice()
elif name == 'rate':
@@ -82,7 +82,7 @@ def getProperty(self, name):
return self._tts.volume()
else:
raise KeyError('unknown property %s' % name)
-
+
def setProperty(self, name, value):
if name == 'voice':
# vol/rate gets reset, so store and restore it
@@ -105,7 +105,7 @@ def speechSynthesizer_didFinishSpeaking_(self, tts, success):
success = True
self._proxy.notify('finished-utterance', completed=success)
self._proxy.setBusy(False)
-
+
def speechSynthesizer_willSpeakWord_ofString_(self, tts, rng, text):
- self._proxy.notify('started-word', location=rng.location,
+ self._proxy.notify('started-word', location=rng.location,
length=rng.length)
View
22 pyttsx/drivers/sapi5.py
@@ -1,7 +1,7 @@
'''
SAPI 5+ driver.
-Copyright (c) 2009 Peter Parente
+Copyright (c) 2009, 2013 Peter Parente
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -54,7 +54,7 @@ def __init__(self, proxy):
# initial rate
self._rateWpm = 200
self.setProperty('voice', self.getProperty('voice'))
-
+
def destroy(self):
self._tts.EventInterests = 0
@@ -63,7 +63,7 @@ def say(self, text):
self._proxy.notify('started-utterance')
self._speaking = True
self._tts.Speak(unicode(text), 19)
-
+
def stop(self):
if not self._speaking:
return
@@ -73,13 +73,13 @@ def stop(self):
def _toVoice(self, attr):
return Voice(attr.Id, attr.GetDescription())
-
+
def _tokenFromId(self, id):
tokens = self._tts.GetVoices()
for token in tokens:
if token.Id == id: return token
raise ValueError('unknown voice id %s', id)
-
+
def getProperty(self, name):
if name == 'voices':
return [self._toVoice(attr) for attr in self._tts.GetVoices()]
@@ -91,7 +91,7 @@ def getProperty(self, name):
return self._tts.Volume/100.0
else:
raise KeyError('unknown property %s' % name)
-
+
def setProperty(self, name, value):
if name == 'voice':
token = self._tokenFromId(value)
@@ -113,20 +113,20 @@ def setProperty(self, name, value):
raise ValueError(str(e))
else:
raise KeyError('unknown property %s' % name)
-
+
def startLoop(self):
first = True
self._looping = True
while self._looping:
- if first:
+ if first:
self._proxy.setBusy(False)
first = False
pythoncom.PumpWaitingMessages()
time.sleep(0.05)
-
+
def endLoop(self):
self._looping = False
-
+
def iterate(self):
self._proxy.setBusy(False)
while 1:
@@ -142,7 +142,7 @@ def setDriver(self, driver):
def OnWord(self, stream, pos, char, length):
self._driver._proxy.notify('started-word', location=char, length=length)
-
+
def OnEndStream(self, stream, pos):
d = self._driver
if d._speaking:
View
64 pyttsx/engine.py
@@ -1,7 +1,7 @@
'''
Speech engine front-end.
-Copyright (c) 2009 Peter Parente
+Copyright (c) 2009, 2013 Peter Parente
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -30,13 +30,13 @@ class Engine(object):
@ivar _driverLoop: Using a driver event loop or not
@type _driverLoop: bool
@ivar _debug: Print exceptions or not
- @type _debug: bool
+ @type _debug: bool
'''
def __init__(self, driverName=None, debug=False):
'''
Constructs a new TTS engine instance.
-
- @param driverName: Name of the platform specific driver to use. If
+
+ @param driverName: Name of the platform specific driver to use. If
None, selects the default driver for the operating system.
@type: str
@param debug: Debugging output enabled or not
@@ -48,11 +48,11 @@ def __init__(self, driverName=None, debug=False):
self._inLoop = False
self._driverLoop = True
self._debug = debug
-
+
def _notify(self, topic, **kwargs):
'''
Invokes callbacks for an event topic.
-
+
@param topic: String event name
@type topic: str
@param kwargs: Values associated with the event
@@ -66,14 +66,14 @@ def _notify(self, topic, **kwargs):
def connect(self, topic, cb):
'''
- Registers a callback for an event topic. Valid topics and their
+ Registers a callback for an event topic. Valid topics and their
associated values:
-
+
started-utterance: name=<str>
started-word: name=<str>, location=<int>, length=<int>
finished-utterance: name=<str>, completed=<bool>
error: name=<str>, exception=<exception>
-
+
@param topic: Event topic name
@type topic: str
@param cb: Callback function
@@ -84,11 +84,11 @@ def connect(self, topic, cb):
arr = self._connects.setdefault(topic, [])
arr.append(cb)
return {'topic' : topic, 'cb' : cb}
-
+
def disconnect(self, token):
'''
Unregisters a callback for an event topic.
-
+
@param token: Token of the callback to unregister
@type token: dict
'''
@@ -104,40 +104,40 @@ def disconnect(self, token):
def say(self, text, name=None):
'''
Adds an utterance to speak to the event queue.
-
+
@param text: Text to sepak
@type text: unicode
- @param name: Name to associate with this utterance. Included in
+ @param name: Name to associate with this utterance. Included in
notifications about this utterance.
@type name: str
'''
self.proxy.say(text, name)
-
+
def stop(self):
'''
Stops the current utterance and clears the event queue.
'''
self.proxy.stop()
-
+
def isBusy(self):
'''
@return: True if an utterance is currently being spoken, false if not
@rtype: bool
'''
return self.proxy.isBusy()
-
+
def getProperty(self, name):
'''
Gets the current value of a property. Valid names and values include:
-
+
voices: List of L{voice.Voice} objects supported by the driver
voice: String ID of the current voice
rate: Integer speech rate in words per minute
volume: Floating point volume of speech in the range [0.0, 1.0]
-
- Numeric values outside the valid range supported by the driver are
+
+ Numeric values outside the valid range supported by the driver are
clipped.
-
+
@param name: Name of the property to fetch
@type name: str
@return: Value associated with the property
@@ -145,19 +145,19 @@ def getProperty(self, name):
@raise KeyError: When the property name is unknown
'''
return self.proxy.getProperty(name)
-
+
def setProperty(self, name, value):
'''
Adds a property value to set to the event queue. Valid names and values
include:
-
+
voice: String ID of the voice
rate: Integer speech rate in words per minute
volume: Floating point volume of speech in the range [0.0, 1.0]
-
- Numeric values outside the valid range supported by the driver are
+
+ Numeric values outside the valid range supported by the driver are
clipped.
-
+
@param name: Name of the property to fetch
@type name: str
@param: Value to set for the property
@@ -165,13 +165,13 @@ def setProperty(self, name, value):
@raise KeyError: When the property name is unknown
'''
self.proxy.setProperty(name, value)
-
+
def runAndWait(self):
'''
Runs an event loop until all commands queued up until this method call
complete. Blocks during the event loop and returns when the queue is
cleared.
-
+
@raise RuntimeError: When the loop is already running
'''
if self._inLoop:
@@ -179,11 +179,11 @@ def runAndWait(self):
self._inLoop = True
self._driverLoop = True
self.proxy.runAndWait()
-
+
def startLoop(self, useDriverLoop=True):
'''
Starts an event loop to process queued commands and callbacks.
-
+
@param useDriverLoop: If True, uses the run loop provided by the driver
(the default). If False, assumes the caller will enter its own
run loop which will pump any events for the TTS engine properly.
@@ -195,18 +195,18 @@ def startLoop(self, useDriverLoop=True):
self._inLoop = True
self._driverLoop = useDriverLoop
self.proxy.startLoop(self._driverLoop)
-
+
def endLoop(self):
'''
Stops a running event loop.
-
+
@raise RuntimeError: When the loop is not running
'''
if not self._inLoop:
raise RuntimeError('run loop not started')
self.proxy.endLoop(self._driverLoop)
self._inLoop = False
-
+
def iterate(self):
'''
Must be called regularly when using an external event loop.
View
14 pyttsx/voice.py
@@ -1,7 +1,7 @@
'''
Voice metadata definition.
-Copyright (c) 2009 Peter Parente
+Copyright (c) 2009, 2013 Peter Parente
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -18,14 +18,14 @@
class Voice(object):
def __init__(self, id, name=None, languages=[], gender=None, age=None):
self.id = id
- self.name = name
+ self.name = name
self.languages = languages
self.gender = gender
self.age = age
-
+
def __str__(self):
- return '''<Voice id=%(id)s
- name=%(name)s
- languages=%(languages)s
- gender=%(gender)s
+ return '''<Voice id=%(id)s
+ name=%(name)s
+ languages=%(languages)s
+ gender=%(gender)s
age=%(age)s>''' % self.__dict__
View
2  setup.py
@@ -1,7 +1,7 @@
'''
pyttsx setup script.
-Copyright (c) 2009 Peter Parente
+Copyright (c) 2009, 2013 Peter Parente
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
View
2  tests/unit/test_all.py
@@ -1,7 +1,7 @@
'''
Runs all unit tests.
-Copyright (c) 2009 Peter Parente
+Copyright (c) 2009, 2013 Peter Parente
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
View
8 tests/unit/test_lifecycle.py
@@ -1,7 +1,7 @@
'''
Tests lifecycle.
-Copyright (c) 2009 Peter Parente
+Copyright (c) 2009, 2013 Peter Parente
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -22,15 +22,15 @@
class TestLifecycle(unittest.TestCase):
def setUp(self):
self.engine = pyttsx.init()
-
+
def tearDown(self):
del self.engine
-
+
def testSeparateDrivers(self):
self.engine2 = pyttsx.init('dummy')
self.assert_(self.engine != self.engine2)
del self.engine2
-
+
def testReuseDriver(self):
self.engine2 = pyttsx.init()
self.assert_(self.engine == self.engine2)
View
14 tests/unit/test_prop.py
@@ -1,7 +1,7 @@
'''
Tests properties.
-Copyright (c) 2009 Peter Parente
+Copyright (c) 2009, 2013 Peter Parente
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -22,10 +22,10 @@
class TestProperties(unittest.TestCase):
def setUp(self):
self.engine = pyttsx.init(debug=False)
-
+
def tearDown(self):
del self.engine
-
+
def testDefaults(self):
voices = self.engine.getProperty('voices')
drate = 200
@@ -60,7 +60,7 @@ def testSetVolume(self):
self.engine.runAndWait()
gvolume = self.engine.getProperty('volume')
self.assertAlmostEqual(volume, gvolume, 4)
-
+
def testSetMultiple(self):
voices = self.engine.getProperty('voices')
self.engine.setProperty('volume', 0.5)
@@ -73,7 +73,7 @@ def testSetMultiple(self):
self.assertAlmostEqual(gvolume, 0.5, 4)
grate = self.engine.getProperty('rate')
self.assert_(grate == 300)
-
+
def testBadVolume(self):
errors = []
def errback(exception, name):
@@ -86,7 +86,7 @@ def errback(exception, name):
self.engine.disconnect(tok)
for error in errors:
self.assert_(isinstance(error, ValueError))
-
+
def testBadRate(self):
errors = []
def errback(exception, name):
@@ -99,7 +99,7 @@ def errback(exception, name):
self.engine.disconnect(tok)
for error in errors:
self.assert_(isinstance(error, ValueError))
-
+
def testBadVoice(self):
errors = []
def errback(exception, name):
View
32 tests/unit/test_say.py
@@ -1,7 +1,7 @@
'''
Tests say.
-Copyright (c) 2009 Peter Parente
+Copyright (c) 2009, 2013 Peter Parente
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -21,7 +21,7 @@
import itertools
class TestSay(unittest.TestCase):
- utters = ['This is the first utterance',
+ utters = ['This is the first utterance',
'The second is an utterance as well']
names = ['utter1', 'utter2']
@@ -40,32 +40,32 @@ def setUp(self):
for event in events:
event['name'] = name
self.correct.append(events)
-
+
self.events = []
self.engine = pyttsx.init(debug=False)
self.engine.connect('started-utterance', self._onUtterStart)
self.engine.connect('started-word', self._onUtterWord)
self.engine.connect('finished-utterance', self._onUtterEnd)
self.engine.connect('error', self._onUtterError)
-
+
def tearDown(self):
del self.engine
-
+
def _onUtterStart(self, **kwargs):
event = {'type' : 'started-utterance'}
event.update(kwargs)
self.events.append(event)
-
+
def _onUtterWord(self, **kwargs):
event = {'type' : 'started-word'}
event.update(kwargs)
self.events.append(event)
-
+
def _onUtterEnd(self, **kwargs):
event = {'type' : 'finished-utterance'}
event.update(kwargs)
self.events.append(event)
-
+
def _onUtterError(self, **kwargs):
event = {'type' : 'error'}
event.update(kwargs)
@@ -80,7 +80,7 @@ def testSay(self):
# event data check
for cevent, tevent in zip(self.correct[0], self.events):
self.assert_(cevent == tevent)
-
+
def testMultipleSay(self):
self.engine.say(self.utters[0], self.names[0])
self.engine.say(self.utters[1], self.names[1])
@@ -91,7 +91,7 @@ def testMultipleSay(self):
correct = itertools.chain(*self.correct)
for cevent, tevent in zip(correct, self.events):
self.assert_(cevent == tevent)
-
+
def testSayTypes(self):
self.engine.say(1.0)
self.engine.say(None)
@@ -117,12 +117,12 @@ def _onWord(**kwargs):
def testStopBeforeSay(self):
self.engine.stop()
self.testSay()
-
+
def testMultipleStopBeforeSay(self):
self.engine.stop()
self.engine.stop()
self.testSay()
-
+
def testStartEndLoop(self):
def _onEnd(**kwargs):
self.engine.endLoop()
@@ -134,11 +134,11 @@ def _onEnd(**kwargs):
# event data check
for cevent, tevent in zip(self.correct[0], self.events):
self.assert_(cevent == tevent)
-
+
def testExternalLoop(self):
def _onEnd(**kwargs):
self.engine.endLoop()
-
+
# kill the engine built by setUp
del self.engine
self.engine = pyttsx.init('dummy')
@@ -155,12 +155,12 @@ def _onEnd(**kwargs):
# event data check
for cevent, tevent in zip(self.correct[0], self.events):
self.assert_(cevent == tevent)
-
+
def testMultipleRuns(self):
self.testSay()
self.events = []
self.testSay()
-
+
def suite():
suite = unittest.TestLoader().loadTestsFromTestCase(TestSay)
#suite = unittest.TestLoader().loadTestsFromName('testExternalLoop', TestSay)
View
2  tests/unit/test_setup.py
@@ -1,7 +1,7 @@
'''
Configures the test fixture.
-Copyright (c) 2009 Peter Parente
+Copyright (c) 2009, 2013 Peter Parente
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
Please sign in to comment.
Something went wrong with that request. Please try again.