fixing tik tok

This commit is contained in:
Luke Robles 2024-07-03 15:25:26 -07:00
parent 2b5facab40
commit 320bfb25a1
2 changed files with 51 additions and 19 deletions

View File

@ -6,6 +6,7 @@ format:
docker run --rm -ti -v ${PWD}:/tmp/python/app pyfound/black:latest_release sh -c "black /tmp/python" docker run --rm -ti -v ${PWD}:/tmp/python/app pyfound/black:latest_release sh -c "black /tmp/python"
clean: clean:
find . -name "*sync-conflict*" -print -delete
docker rm -f dragon-bot-test docker rm -f dragon-bot-test
build-test: build-test:

View File

@ -19,7 +19,7 @@ class Cheeky(commands.Cog):
all_voices = [] all_voices = []
url = "https://weilbyte.github.io/tiktok-tts/" 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")
@ -260,43 +260,74 @@ class Cheeky(commands.Cog):
description="The text you want as TTS", description="The text you want as TTS",
max_length=300, max_length=300,
) )
async def tiktok( @option(
self, "voice",
ctx: commands.Context, description="The voice to use",
input: str, choices=[
voice: discord.Option( "en_us_001",
str, "en_us_006",
autocomplete=discord.utils.basic_autocomplete(get_all_voices), "en_us_007",
description="Tiktok voice to use", "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
file, file_path = tempfile.mkstemp() file, file_path = tempfile.mkstemp()
headers = { headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:127.0) Gecko/20100101 Firefox/127.0",
"Accept": "*/*",
"Accept-Language": "en-US,en;q=0.5",
# 'Accept-Encoding': 'gzip, deflate, br, zstd',
"Content-Type": "application/json", "Content-Type": "application/json",
"Origin": "https://tiktok-tts.weilbyte.dev",
"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",
} }
json_data = { json_data = {"text": input, "voice": voice, "base64": True}
"text": input,
"voice": voice,
}
await ctx.defer()
response = requests.post( response = requests.post(
"https://tiktok-tts.weilnet.workers.dev/api/generation", "https://tiktok-tts.weilbyte.dev/api/generate",
headers=headers, headers=headers,
json=json_data, json=json_data,
).json() ).text
audio_file = base64.b64decode(response["data"]) audio_file = base64.b64decode(response)
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()
os.rename(file_path, file_path + ".mp3") os.rename(file_path, file_path + ".mp3")
await ctx.respond(file=discord.File(file_path + ".mp3")) await ctx.send_followup(file=discord.File(file_path + ".mp3"))
os.remove(file_path + ".mp3") os.remove(file_path + ".mp3")
@commands.slash_command( @commands.slash_command(