📘 Lesson · Lesson 96
Text to Speech
About this Project
💡 At a Glance
Python can convert text into spoken audio using libraries like pyttsx3 (offline) or gTTS (Google, online).
Using pyttsx3 (offline)
Python
import pyttsx3
engine = pyttsx3.init()
engine.say("Hello, welcome to CodingEasily")
engine.runAndWait()Using gTTS (saves MP3)
Python
from gtts import gTTS
tts = gTTS("Hello from CodingEasily")
tts.save("hello.mp3")
print("Audio saved as hello.mp3")Audio saved as hello.mp3
Summary
- pyttsx3 speaks text aloud offline; gTTS creates an MP3 using Google.
- Install with
pip install pyttsx3 gTTS.
💻 Live Code Editor
This page's programs are ready here — run them, edit them, and learn. No installation needed.
Powered by OneCompiler. The code loads into the editor automatically — press Run to see the output. If the editor does not open, open it in a new tab.