Not able to use gTTS module in python

542 Views Asked by At

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.

3

There are 3 best solutions below

0
On BEST ANSWER

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")
0
On

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")
1
On

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