From 7d49589abfc732d92d6940384dad431bdab63b9d Mon Sep 17 00:00:00 2001 From: drPpZero Date: Sat, 27 May 2023 18:07:40 +0900 Subject: [PATCH 1/2] [FIX] fixed https://github.com/kwaroran/RisuAI/issues/122 --- src/ts/characters.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ts/characters.ts b/src/ts/characters.ts index cc529dd1..c761fbbd 100644 --- a/src/ts/characters.ts +++ b/src/ts/characters.ts @@ -41,6 +41,7 @@ export function createNewGroup(){ firstMsgIndex: -1 }) setDatabase(db) + checkCharOrder() return db.characters.length - 1 } From 83ea39bdcb2ed5e85f26d66d4190c0703a4e5e64 Mon Sep 17 00:00:00 2001 From: drPpZero Date: Sat, 27 May 2023 19:13:48 +0900 Subject: [PATCH 2/2] [Fix] Fixed TTS quoted mode Error --- src/ts/process/tts.ts | 4 ++-- src/ts/translator/translator.ts | 13 ++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/ts/process/tts.ts b/src/ts/process/tts.ts index 9d553a83..01ec411b 100644 --- a/src/ts/process/tts.ts +++ b/src/ts/process/tts.ts @@ -12,7 +12,7 @@ export async function sayTTS(character:character,text:string) { if(character.ttsReadOnlyQuoted){ const matches = text.match(/"(.*?)"/g) - if(matches.length > 0){ + if(matches && matches.length > 0){ text = matches.map(match => match.slice(1, -1)).join(""); } else{ @@ -89,7 +89,7 @@ export async function sayTTS(character:character,text:string) { const audioBuffer = await audioContext.decodeAudioData(await getVoice.arrayBuffer()) sourceNode = audioContext.createBufferSource(); sourceNode.buffer = audioBuffer; - sourceNode.connect(audioContext.destination); + sourceNode.connect(audioContext.destination); sourceNode.start(); } } diff --git a/src/ts/translator/translator.ts b/src/ts/translator/translator.ts index 5c995e9e..196c7689 100644 --- a/src/ts/translator/translator.ts +++ b/src/ts/translator/translator.ts @@ -92,8 +92,6 @@ async function jpTrans(text:string) { const url = `https://${host}/translate_a/single?client=gtx&sl=auto&tl=ja&dt=t&q=` + encodeURIComponent(text) - - const f = await fetch(url, { method: "GET", @@ -102,16 +100,17 @@ async function jpTrans(text:string) { const res = await f.json() - - if(typeof(res) === 'string'){ return res as unknown as string - + } - const result = res[0].map((s) => s[0]).filter(Boolean).join(''); + let result = '' + + if (res[0]) { + result = res[0].map((s) => s[0]).filter(Boolean).join(''); + } return result - } \ No newline at end of file