Implementing drivers

You can implement new drivers for the pyttsx.Engine by:

  1. Creating a Python module with the name of your new driver.
  2. Implementing the required driver factory function and class in your module.
  3. Using methods on a pyttsx.driver.DriverProxy instance provided by the pyttsx.Engine to control the event queue and notify applications about events.

The Driver interface

All drivers must implement the following factory function and driver interface.

pyttsx.drivers.buildDriver(proxy : pyttsx.driver.DriverProxy) → pyttsx.drivers.DriverDelegate

Instantiates delegate subclass declared in this module.

Parameters:proxy – Proxy instance provided by a pyttsx.Engine instance.
class pyttsx.drivers.DriverDelegate

Note

The DriverDelegate class is not actually declared in pyttsx.drivers and cannot server as a base class. It is only here for the purpose of documenting the interface all drivers must implement.

__init__(proxy : pyttsx.drivers.DriverProxy, *args, **kwargs) → None

Constructor. Must store the proxy reference.

Parameters:proxy – Proxy instance provided by the buildDriver() function.
destroy()

Optional. Invoked by the pyttsx.driver.DriverProxy when 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 pyttsx.driver.DriverProxy.setBusy() with value True to 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.

Parameters:
  • 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 pyttsx.driver.DriverProxy.setBusy() with value False to pump the command queue.

Parameters:
  • name – Name of the property to change.
  • value – Value to set.
startLoop()

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.DriverProxy object given to the factory function that created this object.

stop()

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 pyttsx.driver.DriverProxy.setBusy() with value False to pump the command queue.

The DriverProxy interface

The 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 pyttsx.Engine instance.

class pyttsx.driver.DriverProxy
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

Project Versions

Table Of Contents

Previous topic

Using pyttsx

Next topic

Changelog

This Page