You can implement new drivers for the
- Creating a Python module with the name of your new driver.
- Implementing the required driver factory function and class in your module.
- Using methods on a
pyttsx.driver.DriverProxyinstance provided by the
pyttsx.Engineto control the event queue and notify applications about events.
The Driver interface¶
All drivers must implement the following factory function and driver interface.
buildDriver(proxy : pyttsx.driver.DriverProxy) → pyttsx.drivers.DriverDelegate¶
Instantiates delegate subclass declared in this module.
Parameters: proxy – Proxy instance provided by a
__init__(proxy : pyttsx.drivers.DriverProxy, *args, **kwargs) → None¶
Constructor. Must store the proxy reference.
Parameters: proxy – Proxy instance provided by the
Optional. Invoked by the
pyttsx.driver.DriverProxywhen it is being destroyed so this delegate can clean up any synthesizer resources. If not implemented, the proxy proceeds safely.
endLoop() → None¶
Immediately ends a running driver event loop.
getProperty(name : string) → object¶
Immediately gets the named property value. At least those properties listed in the
pyttsx.Engine.getProperty()documentation must be supported.
Parameters: name – Name of the property to query. Returns: Value of the property at the time of this invocation.
say(text : unicode, name : string) → None¶
Immediately speaks an utterance. The speech must be output according to the current property values applied at the time of this invocation. Before this method returns, it must invoke
Trueto stall further processing of the command queue until the output completes or is interrupted.
This method must trigger one and only one started-utterance notification when output begins, one started-word notification at the start of each word in the utterance, and a finished-utterance notification when output completes.
- text – Text to speak.
- name – Name to associate with the utterance. Included in notifications about this utterance.
setProperty(name : string, value : object) → None¶
Immediately sets the named property value. At least those properties listed in the
pyttsx.Engine.setProperty()documentation must be supported. After setting the property, the driver must invoke
Falseto pump the command queue.
- name – Name of the property to change.
- value – Value to set.
Immediately starts an event loop. The loop is responsible for sending notifications about utterances and pumping the command queue by using methods on the
pyttsx.driver.DriverProxyobject given to the factory function that created this object.
Immediately stops the current utterance output. This method must trigger a finished-utterance notification if called during on-going output. It must trigger no notification if there is no ongoing output.
After stopping the output and sending any required notification, the driver must invoke
Falseto pump the command queue.
The DriverProxy interface¶
pyttsx.drivers.buildDriver() factory receives an instance of a
DriverProxy class and provides it to the
pyttsx.drivers.DriverDelegate it constructs. The driver delegate can invoke the following public methods on the proxy instance. All other public methods found in the code are reserved for use by an
isBusy() → bool¶
Gets if the proxy is busy and cannot process the next command in the queue or not.
Returns: True means busy, False means idle.
notify(topic : string, **kwargs) → None¶
Fires a notification.
Parameters: topic – The name of the notification. Kwargs: Name/value pairs associated with the topic.
setBusy(busy : bool) → None¶
Sets the proxy to busy so it cannot continue to pump the command queue or idle so it can process the next command.
Parameters: busy – True to set busy, false to set idle