Skip to content
  • SiteMap
  • Our Services
  • Frequently Asked Questions (FAQ)
  • Support
  • About Us

UpdateGadh

Update Your Skills.

  • Home
  • Projects
    •  Blockchain projects
    • Python Project
    • Data Science
    •  Ai projects
    • Machine Learning
    • PHP Project
    • React Projects
    • Java Project
    • SpringBoot
    • JSP Projects
    • Java Script Projects
    • Code Snippet
    • Free Projects
  • Tutorials
    • Ai
    • Machine Learning
    • Advance Python
    • Advance SQL
    • DBMS Tutorial
    • Data Analyst
    • Deep Learning Tutorial
    • Data Science
    • Nodejs Tutorial
  • Blog
  • Contact us
  • Toggle search form
How to Convert Text to Speech in Python

How to Convert Text to Speech in Python

Posted on February 9, 2025February 9, 2025 By Rishabh saini No Comments on How to Convert Text to Speech in Python

How to Convert Text to Speech in Python

In this tutorial, we will learn how to convert human language text into human-like speech using Python.

Sometimes, we prefer listening to content instead of reading. Listening allows multitasking, making it easier to absorb critical information while performing other tasks. Google Text-to-Speech (gTTS) is one of the most widely used Python text-to-speech APIs available.

The gTTS API is easy to use and comes with built-in functions that allow us to save text as an MP3 file. Unlike complex neural network models that require extensive training, gTTS simplifies text-to-speech conversion.

Complete Python Course with Advance topics:-Click here

Features of gTTS API

  • supports a number of languages, such as French, Tamil, German, Hindi, and English.
  • Allows speech playback in slow or normal speed modes.
  • Simple and lightweight solution for converting text into audio.

However, one limitation of gTTS is that the generated speech file cannot be modified once created. To overcome this, we will also explore an offline library called pyttsx3 that provides more control over the generated speech.

Installing Required Libraries

Installing the required Python libraries is the first step.

pip install gTTS
pip install playsound
pip install pyttsx3

Using gTTS for Text-to-Speech Conversion

Let’s look at a basic example to learn how to utilize the gTTS API.

from gtts import gTTS  # Import Google Text-to-Speech API
from playsound import playsound  # Import playsound for playing audio

# Define the text to be converted into speech
text_val = "Welcome to UpdateGadh"

# Define language
language = 'en'

# Convert text to speech
speech_obj = gTTS(text=text_val, lang=language, slow=False)

# Save the converted speech as an audio file
speech_obj.save("welcome.mp3")

# Play the saved audio file
playsound("welcome.mp3")

Output:

The script will generate an MP3 file and play the audio output saying, “Welcome to UpdateGadh.”

Getting the List of Supported Languages

To get the list of available languages in gTTS, use the following code:

from gtts.lang import tts_langs

# Fetch supported languages
gtts_languages = tts_langs()
print(gtts_languages)

This will output a dictionary of supported languages with their respective language codes.

Offline Text-to-Speech Conversion with pyttsx3

If you prefer an offline solution, pyttsx3 is a great alternative. It works with pre-installed TTS engines on your system and provides greater control over speech properties such as speed and voice selection.

Example:

import pyttsx3  # Import pyttsx3 for offline TTS

# Initialize the TTS engine
engine = pyttsx3.init()

# Define the text to be spoken
text = "Python is a powerful programming language"

# Convert text to speech
engine.say(text)

# Play the converted speech
engine.runAndWait()

Adjusting Speech Properties

1. Changing Speech Speed:

engine.setProperty("rate", 150)  # Set speech rate

2. Changing Voice:

voices = engine.getProperty("voices")
engine.setProperty("voice", voices[1].id)  # Change voice

Download New Real Time Projects :-Click here
Complete Advance AI topics:- CLICK HERE

Conclusion

In this lesson, we looked at using Python to turn text into speech. We discussed offline (pyttsx3) and online (gTTS) methods. The gTTS API provides a quick and easy way to generate speech but requires an internet connection, whereas pyttsx3 allows offline conversion with greater control over voice parameters.

With these tools, you can create text-to-speech applications, virtual assistants, or accessibility solutions with ease. Keep experimenting and exploring new ways to integrate TTS into your projects!


how to convert text to speech in python offline
text to speech converter project in python with source code
text-to-speech python code github
How to Convert Text to Speech in Python gtts
How to Convert Text to Speech in Python
how to convert text to speech in python
how to convert text to speech in python offline
How to Convert Text to Speech in Python text-to-speech python pyttsx3
python speech to text real-time
google text-to-speech python
speech recognition python

Post Views: 492
Python Interview Question Tags:convert text to speech, convert text to speech in python, convert text to speech python, convert text to speech using python, how to convert text to speech, how to convert text to speech in python, python text to speech, python text to speech offline, python text to speech pyttsx3, simple text to speech python, text to speech, text to speech conversion using python, text to speech in python, text to speech python, text to speech python project, text to speech using python

Post navigation

Previous Post: Store POS Java Project
Next Post: SQL ORDER BY Clause with Descending Order

More Related Articles

How to Compare Two Lists in Python: Methods and Examples - How to Compare Two Lists in Python How to Compare Two Lists in Python: Methods and Examples Python Interview Question
How to Read a CSV File in Python? - How to Read a CSV File in Python How to Read a CSV File in Python? Python Interview Question
How to Install Tkinter in Python How to Install Tkinter in Python Python Interview Question

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You may also like

  1. How to Install Python on Windows: A Step-by-Step Guide
  2. How to Run Python Program: A Comprehensive Guide for Python Programmers
  3. How to Append Elements to a List in Python
  4. How to Clear the Python Shell
  5. How to Print Patterns in Python
  6. Insertion Sort in Python

Most Viewed Posts

  1. Top Large Language Models in 2025
  2. Online Shopping System using PHP, MySQL with Free Source Code
  3. login form in php and mysql , Step-by-Step with Free Source Code
  4. Flipkart Clone using PHP And MYSQL Free Source Code
  5. News Portal Project in PHP and MySql Free Source Code
  6. User Login & Registration System Using PHP and MySQL Free Code
  7. Top 10 Final Year Project Ideas in Python
  8. Blog Site In PHP And MYSQL With Source Code || Best Project
  9. Online Bike Rental Management System Using PHP and MySQL
  10. E learning Website in php with Free source code
  • AI
  • ASP.NET
  • Blockchain
  • ChatCPT
  • code Snippets
  • Collage Projects
  • Data Science Project
  • Data Science Tutorial
  • DBMS Tutorial
  • Deep Learning Tutorial
  • Final Year Projects
  • Free Projects
  • How to
  • html
  • Interview Question
  • Java Notes
  • Java Project
  • Java Script Notes
  • JAVASCRIPT
  • Javascript Project
  • JSP JAVA(J2EE)
  • Machine Learning Project
  • Machine Learning Tutorial
  • MySQL Tutorial
  • Node.js Tutorial
  • PHP Project
  • Portfolio
  • Python
  • Python Interview Question
  • Python Projects
  • PythonFreeProject
  • React Free Project
  • React Projects
  • Spring boot
  • SQL Tutorial
  • TOP 10
  • Uncategorized
  • Real-Time Medical Queue & Appointment System with Django
  • Online Examination System in PHP with Source Code
  • AI Chatbot for College and Hospital
  • Job Portal Web Application in PHP MySQL
  • Online Tutorial Portal Site in PHP MySQL — Full Project with Source Code

Most Viewed Posts

  • Top Large Language Models in 2025 (8,617)
  • Online Shopping System using PHP, MySQL with Free Source Code (5,227)
  • login form in php and mysql , Step-by-Step with Free Source Code (4,877)

Copyright © 2026 UpdateGadh.

Powered by PressBook Green WordPress theme