기존
This commit is contained in:
51
src/utils/tts/Chzzk.ts
Normal file
51
src/utils/tts/Chzzk.ts
Normal 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 || "오류");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user