🔊 Text-to-Speech Cheatsheet

Make Python talk out loud with pyttsx3. Copy any example into the Editor and press ▶ Run.

🚀 Getting started

Import pyttsx3, start the speech engine, give it something to say, then run it.

import pyttsx3

engine = pyttsx3.init()      # start the speech engine
engine.say("Hello there!")   # queue some words
engine.runAndWait()          # speak them out loud

say(...) only lines the words up — nothing is spoken until you call runAndWait(). Turn your sound on! 🔈

🗣️ Speaking

Queue up one or more phrases, then speak them all with a single runAndWait().

init()Start the engine. Call once, keep the result in a variable.
say(text)Add some words to the queue (does not speak yet).
runAndWait()Speak everything in the queue, and wait until it finishes.
stop()Stop speaking and empty the queue.
import pyttsx3

engine = pyttsx3.init()

# Queue several lines, then speak them in order.
engine.say("Ready?")
engine.say("Steady?")
engine.say("Go!")
engine.runAndWait()
💡 You can mix speech with input() and print() to build a talking quiz.

🎛️ Changing the voice

Adjust how fast and how loud the voice is with setProperty(...).

setProperty("rate", n)Speaking speed in words per minute (~200 is normal). Smaller = slower.
setProperty("volume", v)Loudness from 0.0 (silent) to 1.0 (full).
getProperty("rate")Read the current speed back.
getProperty("volume")Read the current loudness back.
import pyttsx3

engine = pyttsx3.init()
engine.setProperty("rate", 120)     # slow and clear
engine.setProperty("volume", 0.9)   # nice and loud
engine.say("I am speaking slowly and loudly.")
engine.runAndWait()

🧑‍🤝‍🧑 Picking a different voice

The computer usually has more than one voice. List them, then choose one by its id.

getProperty("voices")A list of the available voices. Each one has .id and .name.
setProperty("voice", id)Switch to the voice with that id.
import pyttsx3

engine = pyttsx3.init()

# Keep only the English voices.
voices = engine.getProperty("voices")
english = [v for v in voices if "English" in v.name]

# Print each voice id, then say the same thing with that voice.
for v in english:
    print(v.id, v.name)
    engine.setProperty("voice", v.id)
    engine.say("Do I sound different now?")
    engine.runAndWait()
💡 Which voices you get depends on the computer and browser, so the list can look different from one machine to the next.

🎮 Put it together

A tiny talking greeter that asks your name and says hello.

import pyttsx3

engine = pyttsx3.init()
engine.setProperty("rate", 170)

name = input("What is your name? ")

engine.say("Hello " + name + "! Nice to meet you.")
engine.runAndWait()

print("Done! 👋")

📦 The real pyttsx3 & limits of this version

In this editor, pyttsx3 is a small stand-in built on the browser's own speech engine, so it works online with nothing to install. The examples above use the same commands as the real library, so your code should run elsewhere too.

Using it outside this editor. On a normal computer (for example in Thonny or IDLE), install the official library first:

pip install pyttsx3

The official project lives at pypi.org/project/pyttsx3 with docs at pyttsx3.readthedocs.io. It is fully offline and drives the operating system's speech engine (SAPI5 on Windows, NSSpeechSynthesizer on macOS, espeak on Linux).

What this editor's version does not do. It only copies the most common commands, so a few things from the real library are missing:

Voices differVoices come from your browser and operating system, so the list from getProperty("voices") and how each one sounds will vary by machine. A machine with no installed voice stays silent.
rate is approximateThe browser uses a speed multiplier, not exact words per minute, so setProperty("rate", ...) is only a close match to the real thing.
No saving to a filesave_to_file(...) (writing speech to an audio file) is not supported here. It works in the official library.
No events / callbacksEvent hooks like connect(...) for "started-word" or "finished-utterance" are not available.
No startLoop / pyttsx3 engine loopstartLoop(), endLoop() and iterate() are not implemented.
No voice detailsExtra voice info like languages, gender and age is empty here, even though the attributes exist.
Needs the internet (here)This editor version relies on the browser; the real pyttsx3 on your own computer works fully offline.
💡 Stick to init, say, runAndWait, stop, setProperty and getProperty and your program will behave the same here and with the official library.