Not able to use gTTS module in python

Question:

I tried using gTTS module in python for text to speech. However, when I run the code, I am not able to hear anything.
I referred to https://pypi.org/project/gTTS/ for the installation and documentation.

(I am using Ubuntu)

My code:

from gtts import gTTS
tts = gTTS('hello')
tts.save('hello.mp3')

I am not getting any errors. However, I am not able to hear anything.

Asked By: Ameya Uppina

||

Answers:

gTTS only converts your text to speech and saves it. You have to use another module like playsound or use an audio player to play your audio file. For example:

from gtts import gTTS
import playsound

tts = gTTS(text='hello', lang='en')
tts.save("hello.mp3")
playsound.playsound("hello.mp3")
Answered By: thisisnotshort

gTTS only converts your text to speech and saves it with the help of "tts" API. You have to use another module like playsound to directly play your audio file. For example:

from gtts import gTTS
import playsound
import os

tts = gTTS(text='hello', lang='en')
tts.save("hello.mp3")
playsound.playsound("hello.mp3")
os.remove("hello.mp3")
Answered By: Saurabh Kumar

like this you can add modules in your current library you can run the codes first pip install gTTS

then

you can run pip install playsound

commands then restart your IDE by clicking file->restart ide option

enter image description here

Answered By: Ravindra Narayana
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.