Change language

Converting text to speech in Python

|

GTTS API supports multiple languages ​​including English, Hindi, Tamil, French, German and many more. Speech can be delivered at any of two available audio speeds, fast or slow. However, since the last update, it is not possible to change the voice of the generated sound.

Installation

To install the gTTS API, open a terminal and write

 pip install gTTS 

This works for any platform. 
We are now ready to write a sample program that converts text to speech.

# Import the required module for text
# to speech conversion

from gtts import gTTS

 
# This module is imported so we can
# play the converted audio

import os

  
# Text you want to convert to audio

mytext = ’Welcome to pythonengineering!’

 
# The language you want to convert in

language = ’en’

 
# Transfer of text and language to the engine,
# here we marked slow = False. Which says
# the module that needs the converted audio
# has a high speed

myobj = gTTS (text = mytext, lang = language, slow = False )

 
# Save converted audio to mp3 file with name
# welcome

myobj.save ( "welcome.mp3" )

 
# Play the converted file

os.system ( " mpg321 welcome.mp3 " )

Exit

 The output of the above program should be a voice saying, ’Welcome to pythonengineering!’ 

This article contributed by Achil Goel . If you are as Python.Engineering and would like to contribute, you can also write an article using contribute.python.engineering or by posting the article [email protected] ... See my article appearing on the Python.Engineering homepage and help other geeks.

Please post comments if you find anything wrong or if you would like to share more information on the topic discussed above.

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

Common xlabel/ylabel for matplotlib subplots

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

12 answers

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

12 answers

NUMPYNUMPY

glob exclude pattern

12 answers

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

12 answers

NUMPYNUMPY

Python CSV error: line contains NULL byte

12 answers

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

12 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

sin

How to specify multiple return types using type-hints

exp

Printing words vertically in Python

exp

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

cos

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically