return a list of all possible voices for the tiktok command
This commit is contained in:
parent
ebc0c4c9c3
commit
8c20bf160c
@ -1,16 +1,39 @@
|
||||
from bs4 import BeautifulSoup
|
||||
from discord import option
|
||||
from discord.ext import commands
|
||||
import core_utils
|
||||
import discord
|
||||
import os
|
||||
import random
|
||||
import requests
|
||||
import os
|
||||
|
||||
|
||||
class Cheeky(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot: commands.Bot = bot
|
||||
|
||||
async def get_all_voices(ctx: discord.AutocompleteContext):
|
||||
"""
|
||||
returns a list of all voices you can pass to the API
|
||||
"""
|
||||
|
||||
all_voices = []
|
||||
|
||||
url = "https://weilbyte.github.io/tiktok-tts/"
|
||||
response = requests.get(url)
|
||||
|
||||
soup = BeautifulSoup(response.text, "html.parser")
|
||||
|
||||
all_voices = [
|
||||
item.get("value")
|
||||
for item in soup.find(
|
||||
"select",
|
||||
class_="rounded p-1 bg-slate-100 mt-2 w-full sm:w-1/2",
|
||||
).select("option[value]")
|
||||
]
|
||||
|
||||
return sorted(set(all_voices))
|
||||
|
||||
@commands.slash_command(
|
||||
guild_ids=None,
|
||||
name="decide",
|
||||
@ -177,7 +200,16 @@ class Cheeky(commands.Cog):
|
||||
description="The text you want as TTS",
|
||||
max_length=300,
|
||||
)
|
||||
async def tiktok(self, ctx: commands.Context, input: str):
|
||||
async def tiktok(
|
||||
self,
|
||||
ctx: commands.Context,
|
||||
input: str,
|
||||
voice: discord.Option(
|
||||
str,
|
||||
autocomplete=discord.utils.basic_autocomplete(get_all_voices),
|
||||
description="Tiktok voice to use",
|
||||
),
|
||||
):
|
||||
import tempfile
|
||||
import base64
|
||||
|
||||
@ -189,7 +221,7 @@ class Cheeky(commands.Cog):
|
||||
|
||||
json_data = {
|
||||
"text": input,
|
||||
"voice": "en_us_001",
|
||||
"voice": voice,
|
||||
}
|
||||
|
||||
response = requests.post(
|
||||
|
Loading…
x
Reference in New Issue
Block a user