Fixing the tiktok function for now
This commit is contained in:
parent
d01f96ae8f
commit
480ef5fb46
@ -12,27 +12,27 @@ class Cheeky(commands.Cog):
|
|||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot: commands.Bot = bot
|
self.bot: commands.Bot = bot
|
||||||
|
|
||||||
async def get_all_voices(ctx: discord.AutocompleteContext):
|
# async def get_all_voices(ctx: discord.AutocompleteContext):
|
||||||
"""
|
# """
|
||||||
returns a list of all voices you can pass to the API
|
# returns a list of all voices you can pass to the API
|
||||||
"""
|
# """
|
||||||
|
|
||||||
all_voices = []
|
# all_voices = []
|
||||||
|
|
||||||
url = "https://tiktok-tts.weilbyte.dev/"
|
# url = "https://tiktok-tts.weilbyte.dev/"
|
||||||
response = requests.get(url)
|
# response = requests.get(url)
|
||||||
|
|
||||||
soup = BeautifulSoup(response.text, "html.parser")
|
# soup = BeautifulSoup(response.text, "html.parser")
|
||||||
|
|
||||||
all_voices = [
|
# all_voices = [
|
||||||
item.get("value")
|
# item.get("value")
|
||||||
for item in soup.find(
|
# for item in soup.find(
|
||||||
"select",
|
# "span",
|
||||||
class_="rounded p-1 bg-slate-100 mt-2 w-full sm:w-1/2",
|
# class_="jsx-852f468f0a6b5d08 flex grow",
|
||||||
).select("option[value]")
|
# ).select("option[value]")
|
||||||
]
|
# ]
|
||||||
|
|
||||||
return sorted(set(all_voices))
|
# return sorted(set(all_voices))
|
||||||
|
|
||||||
@commands.slash_command(
|
@commands.slash_command(
|
||||||
guild_ids=None,
|
guild_ids=None,
|
||||||
@ -260,68 +260,40 @@ class Cheeky(commands.Cog):
|
|||||||
description="The text you want as TTS",
|
description="The text you want as TTS",
|
||||||
max_length=300,
|
max_length=300,
|
||||||
)
|
)
|
||||||
@option(
|
async def tiktok(self, ctx: commands.Context, input: str):
|
||||||
"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):
|
|
||||||
import tempfile
|
import tempfile
|
||||||
import base64
|
import base64
|
||||||
|
import json
|
||||||
|
|
||||||
file, file_path = tempfile.mkstemp()
|
file, file_path = tempfile.mkstemp()
|
||||||
|
|
||||||
|
json_data = {"text": input, "voice": "en_us_001"}
|
||||||
|
|
||||||
|
await ctx.defer()
|
||||||
headers = {
|
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": "*/*",
|
||||||
"Accept-Language": "en-US,en;q=0.5",
|
"Accept-Language": "en-US,en;q=0.5",
|
||||||
# 'Accept-Encoding': 'gzip, deflate, br, zstd',
|
# 'Accept-Encoding': 'gzip, deflate, br, zstd',
|
||||||
"Content-Type": "application/json",
|
"Referer": "https://gesserit.co/",
|
||||||
"Origin": "https://tiktok-tts.weilbyte.dev",
|
"Content-Type": "text/plain;charset=UTF-8",
|
||||||
|
"Origin": "https://gesserit.co",
|
||||||
"DNT": "1",
|
"DNT": "1",
|
||||||
"Connection": "keep-alive",
|
"Connection": "keep-alive",
|
||||||
"Referer": "https://tiktok-tts.weilbyte.dev/",
|
|
||||||
"Sec-Fetch-Dest": "empty",
|
"Sec-Fetch-Dest": "empty",
|
||||||
"Sec-Fetch-Mode": "cors",
|
"Sec-Fetch-Mode": "cors",
|
||||||
"Sec-Fetch-Site": "same-origin",
|
"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(
|
response = requests.post(
|
||||||
"https://tiktok-tts.weilbyte.dev/api/generate",
|
"https://gesserit.co/api/tiktok-tts",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
json=json_data,
|
data=json.dumps(json_data),
|
||||||
).text
|
)
|
||||||
|
|
||||||
audio_file = base64.b64decode(response)
|
audio_file = base64.b64decode(response.json()["audioUrl"].split(",")[1])
|
||||||
with open(file_path, "wb") as f:
|
with open(file_path, "wb") as f:
|
||||||
f.write(audio_file)
|
f.write(audio_file)
|
||||||
f.close()
|
f.close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user