/Text-to-Speech-Conversion-Using-Python

This repository contains a simple Python script to generate speech from text using the gTTS (Google Text-to-Speech) library.

Primary LanguagePythonCreative Commons Zero v1.0 UniversalCC0-1.0

Text to Speech Conversion Using Python

This repository contains a simple Python script to generate speech from text using the gTTS (Google Text-to-Speech) library.

image

Table of Contents

Introduction

Text-to-speech (TTS) technology converts written text into spoken words. This project demonstrates how to use the gTTS library to create an MP3 file from a given text string.

Installation

Before you begin, ensure you have Python installed on your system. You can install the gTTS library using pip.

pip install gTTS

Usage

Here is the Python script to generate speech from text:

from gtts import gTTS

language = "en"
text = "Hello, guys how are you doing? I hope you all are doing well."

speech = gTTS(text=text, lang=language, slow=False, tld="com.au")
speech.save("textToSpeech.mp3")

Explanation

  • from gtts import gTTS: Imports the gTTS class from the gTTS module.
  • language = "en": Sets the language to English.
  • text = "Hello, guys how are you doing? I hope you all are doing well.": The text you want to convert to speech.
  • speech = gTTS(text=text, lang=language, slow=False, tld="com.au"): Creates a gTTS object with the specified text, language, speed (slow=False for normal speed), and tld (Top Level Domain) to use the Australian English accent.
  • speech.save("textToSpeech.mp3"): Saves the generated speech to an MP3 file named textToSpeech.mp3.

Running the Script

Save the script to a file, for example text_to_speech.py, and run it using the Python interpreter:

python text_to_speech.py

This will generate an MP3 file named textToSpeech.mp3 in the same directory.