pyttsx3 is a Python library that converts text into spoken words using Windows' built-in voice engine. It works offline and lets you control voice, rate, and volume.
pyttsx3
is a Python library that converts text into spoken words using Windows' built-in voice engine. It works offline and lets you control voice, rate, and volume.
pip install pyttsx3
import pyttsx3
engine = pyttsx3.init() engine.say("Hello, welcome to pyttsx3 text to speech!") engine.runAndWait()
import pyttsx3
engine = pyttsx3.init() voices = engine.getProperty('voices')
for idx, voice in enumerate(voices): print(f"{idx}. Name: {voice.name}, ID: {voice.id}, Lang: {voice.languages}")
You’ll typically see voices like:
0. David - English (US) - Male
1. Zira - English (US) - Female
engine.setProperty('voice', voices[0].id) # Male
engine.setProperty('voice', voices[1].id) # Female
Note - It support only two Types of Voices But you can change Pitch
engine.setProperty('rate', 150) # Default ~200 engine.setProperty('volume', 1.0) # Range: 0.0 to 1.0
engine.say("This is a custom voice with speed and volume.") engine.runAndWait()
pyttsx3
uses system-installed voices. You can add new voices in Windows:
If you want more voices like Hindi, Spanish, French, or regional English (India/UK/US) in your pyttsx3
project, follow these easy steps:
- 🛠️ Open Settings → Press
Win + I
- ⏳ Go to Time & Language > Speech
- 🧩 Scroll down to Manage Voices (in Windows 11)
- ➕ Click Add voices
- 🌐 Choose from languages like:
- ✅ English (India)
- ✅ Hindi
- ✅ Spanish, French, etc.
- ⬇️ Wait for the download to finish
- 🔁 Restart your PC to activate new voices
import pyttsx3
engine = pyttsx3.init() voices = engine.getProperty('voices')
for idx, voice in enumerate(voices): print(f"{idx}. Name: {voice.name}, ID: {voice.id}, Lang: {voice.languages}")
0. Microsoft David Desktop - English (US)
1. Microsoft Zira Desktop - English (US)
2. Microsoft Ravi - English (India)
3. Microsoft Heera - Hindi
4. Microsoft Helena - Spanish (Spain)
👉 Using voice by index:
engine.setProperty('voice', voices[2].id) # Ravi - English (India)
👉 Auto-select by language (e.g., Hindi):
for voice in voices:
if 'hi-IN' in voice.languages or 'Hindi' in voice.name:
engine.setProperty('voice', voice.id)
break
- Use
voice.languages
to detect language codes like'en-IN'
,'hi-IN'
,'es-ES'
- Voices must be installed via Windows Settings first
- Always restart after installing new voices
engine.save_to_file("यह आवाज़ फाइल में सेव होगी", "output.mp3")
engine.runAndWait()
Using pyttsx3
with Windows' built-in and custom-installed voices lets you create advanced text-to-speech apps in multiple languages — fully offline!
import pyttsx3
engine = pyttsx3.init()
voices = engine.getProperty('voices') engine.setProperty('voice', voices[1].id) # Female
engine.setProperty('rate', 140) engine.setProperty('volume', 1.0)
text = "Hello! This is a text-to-speech demo using pyttsx3 on Windows." engine.say(text) engine.runAndWait()
- Use
engine.save_to_file("Text", "output.mp3")
to save TTS as audio file. - Install more Windows voices for different languages.
- Create a voice menu in your app for switching between voices live.
Q. Does pyttsx3 work offline?
✅ Yes, it is fully offline as it uses built-in TTS engines.
Q. Can I change the language?
✅ Yes, if that language's voice is installed on your Windows system.
Q. How to slow down the voice?
🎚️ Use engine.setProperty('rate', 120)
engine.save_to_file("Save this text to file", "speech.mp3")
engine.runAndWait()
pyttsx3
is a powerful and flexible offline TTS library for Python developers on Windows. Customize voices, export audio, and even integrate it in GUIs or games!