lets do it manually then

This commit is contained in:
Nexus 2023-03-16 23:02:18 +00:00
parent dde0ce6ce7
commit 74b6b7026b

View file

@ -4,6 +4,7 @@ import os
import random import random
import re import re
import tempfile import tempfile
import time
import textwrap import textwrap
from datetime import timedelta from datetime import timedelta
from io import BytesIO from io import BytesIO
@ -832,15 +833,18 @@ class OtherCog(commands.Cog):
async def callback(self, interaction: discord.Interaction): async def callback(self, interaction: discord.Interaction):
def _convert(text: str) -> BytesIO(): def _convert(text: str) -> BytesIO():
with tempfile.NamedTemporaryFile(suffix=".mp3") as temp: target_fn = f"jimmy-tts-{ctx.user.id}-{ctx.interaction.id}.mp3"
engine = pyttsx3.init() engine = pyttsx3.init()
_io = BytesIO() _io = BytesIO()
engine.save_to_file(text, temp.name) engine.save_to_file(text, target_fn)
engine.runAndWait() engine.runAndWait()
with open(temp.name, "rb") as f: while not os.path.exists(target_fn):
_io.write(f.read()) time.sleep(0.5)
_io.seek(0) with open(target_fn, "rb") as f:
return _io _io.write(f.read())
os.remove(target_fn)
_io.seek(0)
return _io
await interaction.response.defer() await interaction.response.defer()
_msg = await interaction.followup.send("Converting text to MP3...") _msg = await interaction.followup.send("Converting text to MP3...")