rany2 / edge-tts

Use Microsoft Edge's online text-to-speech service from Python WITHOUT needing Microsoft Edge or Windows or an API key
https://pypi.org/project/edge-tts/
GNU General Public License v3.0
4.24k stars 447 forks source link

How to read speech directly? #148

Closed xiaoqiangclub closed 8 months ago

xiaoqiangclub commented 8 months ago

Is there a way to not save the speech file, but let the program read the speech directly in the Python code? Thank you!

huachuman commented 8 months ago

that would be amazing

rany2 commented 8 months ago

You could use Communicate's steam() to get the audio data as it arrives, afterwards you'll have to figure out how to play it on the fly.

My tip is to use a library to convert the MP3 stream to PCM and have a library that can take PCM data and play it (edit: but basically you can't do this out of the box).