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

the save method executes very slowly #125

Closed ppp1234 closed 11 months ago

ppp1234 commented 11 months ago

Two questions about the save method:

1, the save method executes very slowly (i test both in in windows10 and centos). For example, to convert the text "how are you doing today?", the implementation of communicate = edge_tts.Communicate(TEXT, VOICE) after only 0.009 seconds to get the result, but write the mp3 file took about 1.5 seconds, I do not understand why it will take so long! (my hard drive is SSD)

2、Because it takes too long to write the local mp3 file, I want the save method to return the base64 encoding of the converted audio, how can I modify the program to achieve this?

rany2 commented 11 months ago

I'm a bit confused, how do you think that it took 0.009 seconds to generate a result? That's literally impossible.

Perhaps you forgot to call the async generator stream() function? Have a look at the examples folder for ideas on how to use it.

rany2 commented 11 months ago

I want the save method to return the base64 encoding of the converted audio, how can I modify the program to achieve this?

You can just use the stream() method like in https://github.com/rany2/edge-tts/blob/master/examples/basic_audio_streaming.py but instead of saving to disk you keep appending it some bytes variable and convert it to base64.