mirror of
https://github.com/nexy7574/LCC-bot.git
synced 2024-09-19 18:16:34 +01:00
added better TTS
This commit is contained in:
parent
a12de9c139
commit
b22ee7c36f
4 changed files with 31 additions and 11 deletions
11
Dockerfile
11
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 /
|
||||
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue