mirror of
https://github.com/nexy7574/LCC-bot.git
synced 2024-09-19 18:16:34 +01:00
add text to speech command
This commit is contained in:
parent
90dda967bc
commit
a12de9c139
3 changed files with 38 additions and 4 deletions
|
@ -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...")
|
||||
|
@ -813,6 +811,39 @@ class OtherCog(commands.Cog):
|
|||
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):
|
||||
bot.add_cog(OtherCog(bot))
|
||||
|
|
|
@ -28023,3 +28023,5 @@ cup.shronkservz.tk
|
|||
cakefarts.org
|
||||
newscatinbrazil.com
|
||||
tubgirl.ca
|
||||
redditr.com
|
||||
reditr.com
|
||||
|
|
|
@ -13,3 +13,4 @@ aiofiles==22.1.0
|
|||
httpx==0.23.0
|
||||
fastapi==0.92.0
|
||||
uvicorn==0.20.0
|
||||
gTTS==2.3.1
|
||||
|
|
Loading…
Reference in a new issue