기존
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 || "오류");
|
||||
});
|
||||
});
|
||||
21
src/utils/tts/Google.ts
Normal file
21
src/utils/tts/Google.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import axios from "axios";
|
||||
|
||||
const SPEED = 0.5;
|
||||
|
||||
export const textToSpeech = (text: string) => new Promise<Buffer>(async (res, rej) => {
|
||||
axios.get(`https://www.google.com/speech-api/v1/synthesize?${new URLSearchParams({
|
||||
"text": text,
|
||||
"lang": "ko-kr",
|
||||
"speed": SPEED.toString()
|
||||
}).toString()}`, {
|
||||
headers: {
|
||||
"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",
|
||||
},
|
||||
responseType: "arraybuffer"
|
||||
}).then((val) => {
|
||||
if (val.status !== 200) return rej("오류");
|
||||
return res(val.data);
|
||||
}).catch(() => {
|
||||
return rej("오류");
|
||||
});
|
||||
});
|
||||
24
src/utils/tts/Utils.ts
Normal file
24
src/utils/tts/Utils.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
export const def_replaceObj: Record<string, string> = {
|
||||
"\\?": "물음표",
|
||||
"\\!": "느낌표",
|
||||
"\\~": "물결",
|
||||
"\\+": "더하기",
|
||||
"\\-": "빼기",
|
||||
"\\(": "여는소괄호",
|
||||
"\\)": "닫는소괄호",
|
||||
"\\{": "여는중괄호",
|
||||
"\\}": "닫는중괄호",
|
||||
"\\[": "여는대괄호",
|
||||
"\\]": "닫는대괄호",
|
||||
"ㄹㅇ": "리얼",
|
||||
"ㄲㅂ": "까비",
|
||||
"ㅎㅇ": "하이",
|
||||
"ㅇㅋ": "오키",
|
||||
"ㄴㅇㅅ": "나이스",
|
||||
"ㅇㅈ": "인정",
|
||||
"ㅅㄱ": "수고",
|
||||
"ㅇㅎ": "아하",
|
||||
"ㄱㄱ": "기역기역",
|
||||
"ㅃㄹ": "빨리",
|
||||
"ㄱㅊ": "괜찮",
|
||||
};
|
||||
Reference in New Issue
Block a user