This commit is contained in:
2026-05-26 14:15:09 +09:00
parent 55d402f606
commit d6b36c43c2
33 changed files with 1496 additions and 0 deletions

51
src/utils/tts/Chzzk.ts Normal file
View File

@@ -0,0 +1,51 @@
import axios from "axios";
import { Config } from "../Config";
export enum VoiceType {
// 현재(25.08.27)
유나 = "yuna",
가람 = "garam",
다인 = "dain",
냥냥 = "meow",
경태 = "kyungtae",
악마마몬 = "mammon",
승표 = "seungpyo",
우식 = "woosik",
상도 = "sangdo",
// 이전
하준 = "hajun",
};
const defHeaders = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36",
"Cookie": Object.entries(Config.chzzk).map(([key, value]) => key+'='+value).join(';'),
};
const getToken = () => new Promise<string>((res, rej) => {
axios.get("https://api.chzzk.naver.com/service/v1/alerts/token", {
headers: defHeaders,
responseType: "json"
}).then((val) => {
if (!val.data?.content?.token) return rej(val.data?.message || "오류");
return res(val.data.content.token);
}).catch((err) => {
return rej(err.response?.data?.message || "오류");
});
});
export const textToSpeech = (text: string, voice: VoiceType) => new Promise<Buffer>(async (res, rej) => {
axios.post("https://api.chzzk.naver.com/service/v1/alerts/tts", {
message: text,
token: await getToken().catch(() => "undefined"),
type: "n"+voice
}, {
headers: defHeaders,
responseType: "arraybuffer"
}).then((val) => {
if (val.status !== 200) return rej(val.data?.message || "오류");
return res(val.data);
}).catch((err) => {
return rej(err.response?.data?.message || "오류");
});
});