Ultimate Reference Beginner → Advanced
pyttsx3 is the most reliable offline text-to-speech library for Python. Unlike cloud APIs (Google TTS, AWS Polly), pyttsx3 works without internet, using native OS engines (SAPI5 on Windows, NSSpeech on macOS, eSpeak on Linux). This guide covers everything from pip install pyttsx3 to building JARVIS-like assistants. Created by Natesh M Bhat and maintained by the community, it remains the go‑to for automation, accessibility, and robotics.
pyttsx3 is a Python library that converts text to speech offline. It uses the native speech synthesis engines built into your operating system:
How it works: Your Python script sends text to the engine → engine queues the text → driver communicates with OS speech API → audio is rendered via speakers.
User Text → Engine → Driver → OS Speech API → Speaker
This offline nature makes it perfect for privacy, embedded systems (Raspberry Pi), and low‑latency applications.
Use pip in a virtual environment (recommended):
python -m venv tts_env
source tts_env/bin/activate # Windows: tts_env\Scripts\activate
pip install pyttsx3
pip install --upgrade pyttsx3Verify:
import pyttsx3
engine = pyttsx3.init()
engine.say("Hello world")
engine.runAndWait()Platform specifics: On Linux, install eSpeak: sudo apt install espeak. On macOS, voices are built‑in.
Windows: Uses SAPI5 – fast and supports many voices. macOS: NSSpeechSynthesizer – high‑quality voices. Linux: eSpeak – lightweight but robotic.
The Engine is the core. It manages the queue, event loop, and audio output. Lifecycle: init → configure → speak/run → stop → disconnect.
init() – creates engine instance.say(text) – queues text.runAndWait() – blocks until speech finishes.stop() – clears queue and stops.save_to_file(text, filename) – saves to WAV.getProperty(name) – get rate/volume/voice.setProperty(name, value) – set properties.connect(event, callback) – attach callbacks.disconnect(event, callback) – remove callback.iterate() – process one queue item.startLoop() / endLoop() – manual event loop.isBusy() – check if engine is speaking.Example:
engine = pyttsx3.init()
engine.say("Hello")
engine.runAndWait()
engine.stop()List voices with engine.getProperty('voices'). Select by ID: engine.setProperty('voice', voice_id).
Adjust rate (words/min) and volume (0–1). No direct pitch control, but changing rate affects pitch.
engine.save_to_file('text', 'output.wav'). To get MP3, convert with pydub or FFmpeg.
Hello World: engine.say('Hello'); engine.runAndWait()
Countdown: loop from 10 to 1 and speak.
Reading a file: open text file and speak line by line.
... and many more. (Full examples omitted for brevity but covered in the complete article).
Build a talking calculator, desktop assistant, PDF reader, email reader, RSS news speaker, etc.
JARVIS‑like AI, OCR with voice, face recognition speaker, home automation, hospital announcement system, etc.
Use runAndWait() for simple scripts. For large text, split into chunks. Use threading to avoid blocking GUI.
stop() before exiting.try/except around init().save_to_file for offline audio generation.Offline = no data leaves your device. Ideal for medical, banking, government, education.
| Library | Offline | Voice Quality | Cost |
|---|---|---|---|
| pyttsx3 | ✅ | OS‑dependent | Free |
| gTTS | ❌ | Google (high) | Free |
| Edge TTS | ❌ | Neural | Free |
| Amazon Polly | ❌ | Neural | Pay per use |
Examples: Voice‑enabled alarm clock, accessibility reader for visually impaired, smart mirror announcements, industrial alert system, and a JARVIS assistant.
Beginner: What is pyttsx3? How to install?
Intermediate: How to change voice? Explain event loop.
Advanced: How would you integrate pyttsx3 with an LLM? Discuss thread safety.
Q: Is pyttsx3 free? A: Yes, MIT licensed.
Q: Can I use pyttsx3 without internet? A: Yes.
Q: Does it support Indian accents? A: Depends on OS voices.
Offline AI + edge computing will make pyttsx3 even more relevant. Expect more voices and better integration with local LLMs.
pyttsx3 is a solid, offline TTS engine that every Python developer should know. It’s privacy‑friendly, free, and works on all major platforms. Start with the examples, then build your own voice‑enabled applications.
Next steps: Learn about speech recognition with speech_recognition, combine with pyttsx3 for a full conversational AI.
© 2026 – Ultimate pyttsx3 Guide. All code examples are Python 3.13+ compatible.