Fixing the tiktok function for now
This commit is contained in:
parent
81da1b6fd1
commit
baa1254e99
@ -12,27 +12,27 @@ 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
|
||||
"""
|
||||
# async def get_all_voices(ctx: discord.AutocompleteContext):
|
||||
# """
|
||||
# returns a list of all voices you can pass to the API
|
||||
# """
|
||||
|
||||
all_voices = []
|
||||
# all_voices = []
|
||||
|
||||
url = "https://tiktok-tts.weilbyte.dev/"
|
||||
response = requests.get(url)
|
||||
# url = "https://tiktok-tts.weilbyte.dev/"
|
||||
# response = requests.get(url)
|
||||
|
||||
soup = BeautifulSoup(response.text, "html.parser")
|
||||
# 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]")
|
||||
]
|
||||
# all_voices = [
|
||||
# item.get("value")
|
||||
# for item in soup.find(
|
||||
# "span",
|
||||
# class_="jsx-852f468f0a6b5d08 flex grow",
|
||||
# ).select("option[value]")
|
||||
# ]
|
||||
|
||||
return sorted(set(all_voices))
|
||||
# return sorted(set(all_voices))
|
||||
|
||||
@commands.slash_command(
|
||||
guild_ids=None,
|
||||
@ -260,68 +260,40 @@ class Cheeky(commands.Cog):
|
||||
description="The text you want as TTS",
|
||||
max_length=300,
|
||||
)
|
||||
@option(
|
||||
"voice",
|
||||
description="The voice to use",
|
||||
choices=[
|
||||
"en_us_001",
|
||||
"en_us_006",
|
||||
"en_us_007",
|
||||
"en_us_009",
|
||||
"en_us_010",
|
||||
"en_uk_001",
|
||||
"en_uk_003",
|
||||
"en_au_001",
|
||||
"en_au_002",
|
||||
"en_us_ghostface",
|
||||
"en_us_chewbacca",
|
||||
"en_us_c3po",
|
||||
"en_us_stitch",
|
||||
"en_us_stormtrooper",
|
||||
"en_us_rocket",
|
||||
"en_female_f08_salut_damour",
|
||||
"en_male_m03_lobby",
|
||||
"en_male_m03_sunshine_soon",
|
||||
"en_female_f08_warmy_breeze",
|
||||
"en_female_ht_f08_glorious",
|
||||
"en_male_sing_funny_it_goes_up",
|
||||
"en_male_m2_xhxs_m03_silly",
|
||||
"en_female_ht_f08_wonderful_world",
|
||||
],
|
||||
required=True,
|
||||
)
|
||||
async def tiktok(self, ctx: commands.Context, input: str, voice: str):
|
||||
async def tiktok(self, ctx: commands.Context, input: str):
|
||||
import tempfile
|
||||
import base64
|
||||
import json
|
||||
|
||||
file, file_path = tempfile.mkstemp()
|
||||
|
||||
json_data = {"text": input, "voice": "en_us_001"}
|
||||
|
||||
await ctx.defer()
|
||||
headers = {
|
||||
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:127.0) Gecko/20100101 Firefox/127.0",
|
||||
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:129.0) Gecko/20100101 Firefox/129.0",
|
||||
"Accept": "*/*",
|
||||
"Accept-Language": "en-US,en;q=0.5",
|
||||
# 'Accept-Encoding': 'gzip, deflate, br, zstd',
|
||||
"Content-Type": "application/json",
|
||||
"Origin": "https://tiktok-tts.weilbyte.dev",
|
||||
"Referer": "https://gesserit.co/",
|
||||
"Content-Type": "text/plain;charset=UTF-8",
|
||||
"Origin": "https://gesserit.co",
|
||||
"DNT": "1",
|
||||
"Connection": "keep-alive",
|
||||
"Referer": "https://tiktok-tts.weilbyte.dev/",
|
||||
"Sec-Fetch-Dest": "empty",
|
||||
"Sec-Fetch-Mode": "cors",
|
||||
"Sec-Fetch-Site": "same-origin",
|
||||
"Priority": "u=1",
|
||||
"Priority": "u=0",
|
||||
# Requests doesn't support trailers
|
||||
# 'TE': 'trailers',
|
||||
}
|
||||
|
||||
json_data = {"text": input, "voice": voice, "base64": True}
|
||||
|
||||
await ctx.defer()
|
||||
response = requests.post(
|
||||
"https://tiktok-tts.weilbyte.dev/api/generate",
|
||||
"https://gesserit.co/api/tiktok-tts",
|
||||
headers=headers,
|
||||
json=json_data,
|
||||
).text
|
||||
data=json.dumps(json_data),
|
||||
)
|
||||
|
||||
audio_file = base64.b64decode(response)
|
||||
audio_file = base64.b64decode(response.json()["audioUrl"].split(",")[1])
|
||||
with open(file_path, "wb") as f:
|
||||
f.write(audio_file)
|
||||
f.close()
|
||||
|
Loading…
x
Reference in New Issue
Block a user