From 8fd8022115f8e9196fbaa4a24ce4c6f050d5508d Mon Sep 17 00:00:00 2001 From: nex Date: Thu, 16 Mar 2023 22:49:11 +0000 Subject: [PATCH] fix speech gen --- cogs/other.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/cogs/other.py b/cogs/other.py index b9c1ac4..8d7a14a 100644 --- a/cogs/other.py +++ b/cogs/other.py @@ -832,12 +832,15 @@ class OtherCog(commands.Cog): async def callback(self, interaction: discord.Interaction): def _convert(text: str) -> BytesIO(): - engine = pyttsx3.init() - _io = BytesIO() - engine.save_to_file(text, _io) - engine.runAndWait() - _io.seek(0) - return _io + with tempfile.makestemp(suffix=".mp3") as temp: + engine = pyttsx3.init() + _io = BytesIO() + engine.save_to_file(text, temp) + engine.runAndWait() + with open(temp, "rb") as f: + _io.write(f.read()) + _io.seek(0) + return _io await interaction.response.defer() _msg = await interaction.followup.send("Converting text to MP3...")