From a12de9c139dea9773a178e4b2755fde63f41255e Mon Sep 17 00:00:00 2001 From: EEKIM10 Date: Thu, 16 Mar 2023 21:45:01 +0000 Subject: [PATCH] add text to speech command --- cogs/other.py | 39 +++++++++++++++++++++++++++++++++++---- domains.txt | 2 ++ requirements.txt | 1 + 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/cogs/other.py b/cogs/other.py index 9ff960a..9c31c07 100644 --- a/cogs/other.py +++ b/cogs/other.py @@ -6,6 +6,7 @@ import re import tempfile import textwrap from datetime import timedelta +from io import BytesIO import dns.resolver from dns import asyncresolver @@ -27,6 +28,7 @@ from selenium.webdriver.chrome.options import Options as ChromeOptions from selenium.webdriver.chrome.service import Service as ChromeService from selenium.webdriver.firefox.options import Options as FirefoxOptions from selenium.webdriver.firefox.service import Service as FirefoxService +from gtts import gTTS, gTTSError # from selenium.webdriver.ie @@ -759,10 +761,6 @@ class OtherCog(commands.Cog): options.extend(["--proxy", proxy]) if video_format: options.extend(["--format", video_format]) - # if audio_quality: - # options.extend(["--audio-quality", str(audio_quality)]) - # if extract_audio: - # options.append("--extract-audio") await ctx.defer() await ctx.edit(content="Downloading video...") @@ -812,6 +810,39 @@ class OtherCog(commands.Cog): if not files: return await ctx.edit(content="No files found.") await ctx.edit(content="Here's your video!", files=files) + + @commands.slash_command(name="text-to-mp3") + @commands.cooldown(5, 600, commands.BucketType.user) + async def text_to_mp3(self, ctx: discord.ApplicationContext): + """Converts text to MP3. 5 uses per 10 minutes.""" + _bot = self.bot + class TextModal(discord.ui.Modal): + def __init__(self): + super().__init__( + discord.ui.InputText( + label="Text", + placeholder="Enter text to read", + min_length=1, + max_length=4000, + style=discord.InputTextStyle.long + ), + title="Convert text to an MP3" + ) + + async def callback(self, interaction: discord.Interaction): + await interaction.response.defer() + _msg = await interaction.followup.send("Converting text to MP3...") + text = self.children[0].value + instance = gTTS(text=text, lang="en") + _io = BytesIO() + await _bot.loop.run_in_executor(None, instance.write_to_fp, _io) + _io.seek(0) + await _msg.edit( + content="Here's your MP3!", + file=discord.File(_io, filename="text.mp3") + ) + + await ctx.send_modal(TextModal()) def setup(bot): diff --git a/domains.txt b/domains.txt index e3cd49d..5b5e086 100644 --- a/domains.txt +++ b/domains.txt @@ -28023,3 +28023,5 @@ cup.shronkservz.tk cakefarts.org newscatinbrazil.com tubgirl.ca +redditr.com +reditr.com diff --git a/requirements.txt b/requirements.txt index 69cb603..3d7eaf8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,3 +13,4 @@ aiofiles==22.1.0 httpx==0.23.0 fastapi==0.92.0 uvicorn==0.20.0 +gTTS==2.3.1