added better TTS

This commit is contained in:
Nexus 2023-03-16 22:45:04 +00:00
parent a12de9c139
commit b22ee7c36f
4 changed files with 31 additions and 11 deletions

View file

@ -2,15 +2,17 @@ FROM python:3.11-bullseye
COPY config.py / 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 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 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 \ build-essential \
libpq-dev \ libpq-dev \
python3-dev \ python3-dev \
@ -19,7 +21,8 @@ RUN apt update && apt install -y \
python3-wheel \ python3-wheel \
python3-venv \ python3-venv \
firefox-esr \ firefox-esr \
google-chrome-stable google-chrome-stable \
espeak
COPY requirements.txt / COPY requirements.txt /

View file

@ -11,6 +11,7 @@ from io import BytesIO
import dns.resolver import dns.resolver
from dns import asyncresolver from dns import asyncresolver
import aiofiles import aiofiles
import pyttsx3
from time import time, time_ns from time import time, time_ns
from typing import Literal from typing import Literal
from typing import Tuple, Optional, Dict from typing import Tuple, Optional, Dict
@ -830,16 +831,31 @@ class OtherCog(commands.Cog):
) )
async def callback(self, interaction: discord.Interaction): 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() await interaction.response.defer()
_msg = await interaction.followup.send("Converting text to MP3...") _msg = await interaction.followup.send("Converting text to MP3...")
text = self.children[0].value text_pre = self.children[0].value
instance = gTTS(text=text, lang="en") _io = await _bot.loop.run_in_executor(None, _convert, text_pre)
_io = BytesIO() fn = ""
await _bot.loop.run_in_executor(None, instance.write_to_fp, _io) _words = text_pre.split()
_io.seek(0) 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( await _msg.edit(
content="Here's your MP3!", content="Here's your MP3!",
file=discord.File(_io, filename="text.mp3") file=discord.File(_io, filename=fn + ".mp3")
) )
await ctx.send_modal(TextModal()) await ctx.send_modal(TextModal())

View file

@ -13,4 +13,4 @@ aiofiles==22.1.0
httpx==0.23.0 httpx==0.23.0
fastapi==0.92.0 fastapi==0.92.0
uvicorn==0.20.0 uvicorn==0.20.0
gTTS==2.3.1 pyttsx3==2.90

View file

@ -56,6 +56,7 @@ def ping():
@app.get("/auth") @app.get("/auth")
async def authenticate(req: Request, code: str = None, state: str = None): async def authenticate(req: Request, code: str = None, state: str = None):
"""Begins Oauth flow (browser only)"""
if not OAUTH_ENABLED: if not OAUTH_ENABLED:
raise HTTPException( raise HTTPException(
501, 501,