Commit c954f1b4 authored by Timothy J. Baek's avatar Timothy J. Baek
Browse files

refac

parent edbd07f8
...@@ -234,35 +234,40 @@ ...@@ -234,35 +234,40 @@
console.log(sentences); console.log(sentences);
sentencesAudio = sentences.reduce((a, e, i, arr) => { if (sentences.length > 0) {
a[i] = null; sentencesAudio = sentences.reduce((a, e, i, arr) => {
return a; a[i] = null;
}, {}); return a;
}, {});
let lastPlayedAudioPromise = Promise.resolve(); // Initialize a promise that resolves immediately
let lastPlayedAudioPromise = Promise.resolve(); // Initialize a promise that resolves immediately
for (const [idx, sentence] of sentences.entries()) {
const res = await synthesizeOpenAISpeech( for (const [idx, sentence] of sentences.entries()) {
localStorage.token, const res = await synthesizeOpenAISpeech(
$settings?.audio?.tts?.voice ?? $config?.audio?.tts?.voice, localStorage.token,
sentence $settings?.audio?.tts?.voice ?? $config?.audio?.tts?.voice,
).catch((error) => { sentence
toast.error(error); ).catch((error) => {
toast.error(error);
speaking = null;
loadingSpeech = false; speaking = null;
loadingSpeech = false;
return null;
}); return null;
});
if (res) {
const blob = await res.blob(); if (res) {
const blobUrl = URL.createObjectURL(blob); const blob = await res.blob();
const audio = new Audio(blobUrl); const blobUrl = URL.createObjectURL(blob);
sentencesAudio[idx] = audio; const audio = new Audio(blobUrl);
loadingSpeech = false; sentencesAudio[idx] = audio;
lastPlayedAudioPromise = lastPlayedAudioPromise.then(() => playAudio(idx)); loadingSpeech = false;
lastPlayedAudioPromise = lastPlayedAudioPromise.then(() => playAudio(idx));
}
} }
} else {
speaking = null;
loadingSpeech = false;
} }
} else { } else {
let voices = []; let voices = [];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment