From b8073fe2909f70b9e8976a2da1e692589b770e0a Mon Sep 17 00:00:00 2001 From: nex Date: Thu, 16 Mar 2023 23:49:37 +0000 Subject: [PATCH] allow user-controlled speed --- cogs/other.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cogs/other.py b/cogs/other.py index 29f55a4..86e8368 100644 --- a/cogs/other.py +++ b/cogs/other.py @@ -814,8 +814,18 @@ class OtherCog(commands.Cog): @commands.slash_command(name="text-to-mp3") @commands.cooldown(5, 600, commands.BucketType.user) - async def text_to_mp3(self, ctx: discord.ApplicationContext): + async def text_to_mp3( + self, + ctx: discord.ApplicationContext, + speed: discord.Option( + int, + "The speed of the voice. Default is 150.", + required=False, + default=150 + ) + ): """Converts text to MP3. 5 uses per 10 minutes.""" + speed = min(300, max(100, speed)) _bot = self.bot class TextModal(discord.ui.Modal): def __init__(self): @@ -836,7 +846,7 @@ class OtherCog(commands.Cog): _bot.console.log("Starting pyttsx3") engine = pyttsx3.init() # engine.setProperty("voice", "english-north") - engine.setProperty("rate", 150) + engine.setProperty("rate", speed) _io = BytesIO() _bot.console.log("Saving to file") engine.save_to_file(text, target_fn)