[Fix] NAI TTS Cors ERR

Signed-off-by: hashcoko <hashcoko@gmail.com>
This commit is contained in:
hashcoko
2023-11-28 03:45:34 +09:00
parent 9432b63606
commit 5983e3883f
3 changed files with 11 additions and 9 deletions

2
.gitignore vendored
View File

@@ -6,7 +6,7 @@ yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
package-lock.json
node_modules
dist/
save/

View File

@@ -12,11 +12,11 @@
import VisualNovelMain from "../VisualNovel/VisualNovelMain.svelte";
let openChatList = false
$:{
if ($DataBase.translatorType === 'submodel'){
$DataBase.useStreaming = false
}
}
const wallPaper = `background: url(${defaultWallpaper})`
const externalStyles =
("background: " + ($DataBase.textScreenColor ? ($DataBase.textScreenColor + '80') : "rgba(0,0,0,0.8)") + ';\n')

View File

@@ -141,15 +141,16 @@ export async function sayTTS(character:character,text:string) {
}
case 'novelai': {
const audioContext = new AudioContext();
const response = await fetch(`https://api.novelai.net/ai/generate-voice?text=${text}&voice=-1&seed=${character.naittsConfig.voice}&opus=false&version=${character.naittsConfig.version}`, {
const response = await globalFetch(`https://api.novelai.net/ai/generate-voice?text=${text}&voice=-1&seed=${character.naittsConfig.voice}&opus=false&version=${character.naittsConfig.version}`, {
method: 'GET',
headers: {
"Authorization": "Bearer " + db.NAIApiKey,
}
},
rawResponse: true
});
if (response.status === 200 && response.headers.get('content-type') === 'audio/mpeg') {
const audioBuffer = await response.arrayBuffer();
if (response.ok) {
const audioBuffer = response.data.buffer;
audioContext.decodeAudioData(audioBuffer, (decodedData) => {
const sourceNode = audioContext.createBufferSource();
sourceNode.buffer = decodedData;
@@ -158,6 +159,7 @@ export async function sayTTS(character:character,text:string) {
});
} else {
alertError("Error fetching or decoding audio data");
console.log(response);
}
break;
}