Using Pyttsx3 - Pyttsx3 2.6 Documentation
Using Pyttsx3 - Pyttsx3 2.6 Documentation
6 documentation
Using pyttsx3
An application invokes the pyttsx3.init() factory function to get a reference to a pyttsx3.Engine in-
stance. During construction, the engine initializes a pyttsx3.driver.DriverProxy object responsible for
loading a speech engine driver implementation from the pyttsx3.drivers module. After construction, an
application uses the engine object to register and unregister event callbacks; produce and stop speech; get
and set speech engine properties; and start and stop event loops.
Parameters: driverName –
Name of the pyttsx3.drivers module to load and use. Defaults to the best available
driver for the platform, currently:
The following are the valid topics and their callback signatures.
started-utterance
Fired when the engine begins speaking an utterance. The associated callback must have the
folowing signature.
https://pyttsx3.readthedocs.io/en/latest/engine.html#examples 1/5
12/6/23, 10:15 Using pyttsx3 — pyttsx3 2.6 documentation
finished-utterance
Fired when the engine finishes speaking an utterance. The associated callback must have the
folowing signature.
endLoop () → None
Ends a running event loop. If startLoop() was called with useDriverLoop set to True, this method
stops processing of engine commands and immediately exits the event loop. If it was called with
False, this method stops processing of engine commands, but it is up to the caller to end the exter-
nal event loop it started.
rate
Integer speech rate in words per minute. Defaults to 200 word per minute.
voice
String identifier of the active voice.
voices
List of pyttsx3.voice.Voice descriptor objects.
volume
Floating point volume in the range of 0.0 to 1.0 inclusive. Defaults to 1.0.
isBusy () → bool
Gets if the engine is currently busy speaking an utterance or not.
https://pyttsx3.readthedocs.io/en/latest/engine.html#examples 2/5
12/6/23, 10:15 Using pyttsx3 — pyttsx3 2.6 documentation
Blocks while processing all currently queued commands. Invokes callbacks for engine notifications
appropriately. Returns when all commands queued before this call are emptied from the queue.
say (text : unicode, name : string) → None
Queues a command to speak an utterance. The speech is output according to the properties set be-
fore this command in the queue.
rate
Integer speech rate in words per minute.
voice
String identifier of the active voice.
volume
Floating point volume in the range of 0.0 to 1.0 inclusive.
Parameters: useDriverLoop – True to use the loop provided by the selected driver. False to
indicate the caller will enter its own loop after invoking this method. The caller’s
loop must pump events for the driver in use so that pyttsx3 notifications are deliv-
ered properly (e.g., SAPI5 requires a COM message pump). Defaults to True.
stop () → None
Stops the current utterance and clears the command queue.
age
Integer age of the voice in years. Defaults to None if unknown.
gender
String gender of the voice: male, female, or neutral. Defaults to None if unknown.
id
String identifier of the voice. Used to set the active voice via v: latest
pyttsx3.engine.Engine.setPropertyValue(). This attribute is always defined.
https://pyttsx3.readthedocs.io/en/latest/engine.html#examples 3/5
12/6/23, 10:15 Using pyttsx3 — pyttsx3 2.6 documentation
languages
List of string languages supported by this voice. Defaults to an empty list of unknown.
name
Human readable name of the voice. Defaults to None if unknown.
Examples
Speaking text
import pyttsx3
engine = pyttsx3.init()
engine.say('Sally sells seashells by the seashore.')
engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()
Interrupting an utterance
import pyttsx3
def onWord(name, location, length):
print 'word', name, location, length
if location > 10:
engine.stop()
engine = pyttsx3.init()
engine.connect('started-word', onWord)
engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()
v: latest
Changing voices
https://pyttsx3.readthedocs.io/en/latest/engine.html#examples 4/5
12/6/23, 10:15 Using pyttsx3 — pyttsx3 2.6 documentation
engine = pyttsx3.init()
voices = engine.getProperty('voices')
for voice in voices:
engine.setProperty('voice', voice.id)
engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()
Changing volume
engine = pyttsx3.init()
volume = engine.getProperty('volume')
engine.setProperty('volume', volume-0.25)
engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()
v: latest
https://pyttsx3.readthedocs.io/en/latest/engine.html#examples 5/5