How can I save bytes more easily?
Closed this issue · 4 comments
bbhxwl commented
def text_to_data(text):
communicate = edge_tts.Communicate(text, "zh-CN-XiaoxiaoNeural")
if not os.path.exists("temp"):
os.makedirs("temp")
temp_file_path = os.path.join("temp", f"{uuid.uuid4().hex}.mp3")
communicate.save_sync(audio_fname=temp_file_path)
with open(temp_file_path, "rb") as f:
audio_bytes = f.read()
os.remove(temp_file_path)
return audio_bytes
rany2 commented
Something like this:
import edge_tts
import io
def text_to_data(text):
communicate = edge_tts.Communicate(text, "zh-CN-XiaoxiaoNeural")
audio_bytes = io.BytesIO()
for chunk in communicate.stream_sync():
if chunk["type"] == "audio":
audio_bytes.write(chunk["data"])
audio_bytes.seek(0)
return audio_bytes.getvalue()
rany2 commented
It might make sense to allow save to take any file object including io.BytesIO()
instead of requiring it to be a file path.
bbhxwl commented
It might make sense to allow save to take any file object including
io.BytesIO()
instead of requiring it to be a file path.
Thank you, is it possible to use this library offline?
rany2 commented
No, it's not possible.