diff --git a/Dockerfile b/Dockerfile index 1a5680c..5a6f0ae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,15 +2,17 @@ FROM python:3.11-bullseye COPY config.py / -RUN apt update +RUN apt-get update -RUN apt install software-properties-common apt-transport-https wget ca-certificates -y +RUN apt-get install software-properties-common apt-transport-https wget ca-certificates -y RUN wget -O- https://dl.google.com/linux/linux_signing_key.pub | gpg --dearmor | tee /usr/share/keyrings/google-chrome.gpg RUN echo 'deb [arch=amd64 signed-by=/usr/share/keyrings/google-chrome.gpg] http://dl.google.com/linux/chrome/deb/ stable main' | tee /etc/apt/sources.list.d/google-chrome.list -RUN apt update && apt install -y \ +RUN apt-get update + +RUN apt-get install -y \ build-essential \ libpq-dev \ python3-dev \ @@ -19,7 +21,8 @@ RUN apt update && apt install -y \ python3-wheel \ python3-venv \ firefox-esr \ - google-chrome-stable + google-chrome-stable \ + espeak COPY requirements.txt / diff --git a/cogs/other.py b/cogs/other.py index 9c31c07..b9c1ac4 100644 --- a/cogs/other.py +++ b/cogs/other.py @@ -11,6 +11,7 @@ from io import BytesIO import dns.resolver from dns import asyncresolver import aiofiles +import pyttsx3 from time import time, time_ns from typing import Literal from typing import Tuple, Optional, Dict @@ -830,16 +831,31 @@ 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 + 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) + text_pre = self.children[0].value + _io = await _bot.loop.run_in_executor(None, _convert, text_pre) + fn = "" + _words = text_pre.split() + while len(fn) < 28: + try: + word = _words.pop(0) + except IndexError: + break + if len(fn) + len(word) + 1 > 28: + continue + fn += word + "-" await _msg.edit( content="Here's your MP3!", - file=discord.File(_io, filename="text.mp3") + file=discord.File(_io, filename=fn + ".mp3") ) await ctx.send_modal(TextModal()) diff --git a/requirements.txt b/requirements.txt index 3d7eaf8..0acccb7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,4 +13,4 @@ aiofiles==22.1.0 httpx==0.23.0 fastapi==0.92.0 uvicorn==0.20.0 -gTTS==2.3.1 +pyttsx3==2.90 diff --git a/web/server.py b/web/server.py index bab15de..d858c60 100644 --- a/web/server.py +++ b/web/server.py @@ -56,6 +56,7 @@ def ping(): @app.get("/auth") async def authenticate(req: Request, code: str = None, state: str = None): + """Begins Oauth flow (browser only)""" if not OAUTH_ENABLED: raise HTTPException( 501,