Is there any other way to play sound in pyton from gtts? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Is there any other way to play sound in pyton from gtts?

I was working on a little project, and I am using google text to speech (gtts) module to convert words to sound, then I had to save that sound as mp3 then play it and delete it after, is there any idea to make it work faster? import os import gtts from playsound import playsound def say(text) : file = "x.mp3" tts = gtts.gTTS(text) tts.save(file) playsound(file) os.remove(file)

9th Apr 2021, 7:23 PM
Saeed Alqassabi
Saeed Alqassabi - avatar
4 Answers
+ 1
You want to directly play the sound without saving it.
19th Apr 2021, 4:55 PM
KUMAR SHANU
KUMAR SHANU - avatar
+ 1
Read documentation of gtts you will probably find function for that use that one instead of gtts.gTTS()
19th Apr 2021, 4:56 PM
KUMAR SHANU
KUMAR SHANU - avatar
+ 1
Will this work? ```py def say(text): playsound(gtts.gTTS(text)) ```
19th Apr 2021, 4:58 PM
KUMAR SHANU
KUMAR SHANU - avatar
+ 1
KUMAR SHANU I actually tried doing directly using playsound, It didn't work. I saw the documentation and they use the same way that I did there, unless if we were talking about gtts-cli, but I don't think it is better than the ordinary way.
24th Apr 2021, 7:28 PM
Saeed Alqassabi
Saeed Alqassabi - avatar