Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to directly play speech in python without saving to mp3?

Tags:

python

gtts

I am trying into convert text to speech in Python using the gTTS module. Is there a method you can use which does not involve saving the audio to an mp3 file and instead plays the it directly? I have looked online for a while but I still can't find a method which completely avoids saving to files. Thanks!

like image 860
Random_Coding_Cactus Avatar asked Sep 14 '25 03:09

Random_Coding_Cactus


1 Answers

Try using pyttsx3. Usage:

import pyttsx3
engine = pyttsx3.init()
engine.say("I will speak this text")
engine.runAndWait()

This does not save audio to an mp3 file and works offline.

Link to source code

like image 133
thisisnotshort Avatar answered Sep 15 '25 17:09

thisisnotshort