From fce729829b5cbc29684c129c9b0d5a91498fd6fd Mon Sep 17 00:00:00 2001 From: VR <101288516+VillainsRule@users.noreply.github.com> Date: Tue, 12 Aug 2025 09:31:22 -0400 Subject: [PATCH] add tiktokTTS plugin (#342) * add tiktokTTS plugin * folder --------- Co-authored-by: thororen1234 <78185467+thororen1234@users.noreply.github.com> --- src/equicordplugins/tiktokTTS/index.ts | 45 ++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/equicordplugins/tiktokTTS/index.ts diff --git a/src/equicordplugins/tiktokTTS/index.ts b/src/equicordplugins/tiktokTTS/index.ts new file mode 100644 index 000000000..41f988f30 --- /dev/null +++ b/src/equicordplugins/tiktokTTS/index.ts @@ -0,0 +1,45 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2025 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { EquicordDevs } from "@utils/constants"; +import { getCurrentChannel } from "@utils/discord"; +import definePlugin from "@utils/types"; + +async function readOutText(text: string): Promise { + const mp3Response = await fetch("https://tiktok-tts.weilnet.workers.dev/api/generation", { + body: JSON.stringify({ text: text, voice: "en_us_001" }), + headers: { "Content-Type": "application/json" }, + method: "POST" + }); + + const mp3JSON = await mp3Response.json(); + + const audioElement = new Audio(); + + audioElement.src = `data:audio/mpeg;base64,${mp3JSON.data}`; + audioElement.volume = 0.5; + audioElement.onended = () => audioElement.remove(); + + document.body.appendChild(audioElement); + + audioElement.play(); +} + +export default definePlugin({ + name: "TiktokTTS", + description: "Reads out chat messages with the good ol' Tiktok TTS voice :sob:", + authors: [EquicordDevs.VillainsRule], + flux: { + async MESSAGE_CREATE({ optimistic, type, message }) { + if (optimistic || type !== "MESSAGE_CREATE") return; + if (message.state === "SENDING") return; + if (!message.content || message.content.length < 1 || message.content.length > 300) return; + if (message.channel_id !== getCurrentChannel()?.id) return; + + readOutText(message.content); + } + } +});