mirror of
https://github.com/open-webui/open-webui
synced 2025-06-26 18:26:48 +00:00
refac
This commit is contained in:
parent
edbd07f893
commit
c954f1b4de
@ -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()) {
|
for (const [idx, sentence] of sentences.entries()) {
|
||||||
const res = await synthesizeOpenAISpeech(
|
const res = await synthesizeOpenAISpeech(
|
||||||
localStorage.token,
|
localStorage.token,
|
||||||
$settings?.audio?.tts?.voice ?? $config?.audio?.tts?.voice,
|
$settings?.audio?.tts?.voice ?? $config?.audio?.tts?.voice,
|
||||||
sentence
|
sentence
|
||||||
).catch((error) => {
|
).catch((error) => {
|
||||||
toast.error(error);
|
toast.error(error);
|
||||||
|
|
||||||
speaking = null;
|
speaking = null;
|
||||||
loadingSpeech = false;
|
loadingSpeech = false;
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
const blob = await res.blob();
|
const blob = await res.blob();
|
||||||
const blobUrl = URL.createObjectURL(blob);
|
const blobUrl = URL.createObjectURL(blob);
|
||||||
const audio = new Audio(blobUrl);
|
const audio = new Audio(blobUrl);
|
||||||
sentencesAudio[idx] = audio;
|
sentencesAudio[idx] = audio;
|
||||||
loadingSpeech = false;
|
loadingSpeech = false;
|
||||||
lastPlayedAudioPromise = lastPlayedAudioPromise.then(() => playAudio(idx));
|
lastPlayedAudioPromise = lastPlayedAudioPromise.then(() => playAudio(idx));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
speaking = null;
|
||||||
|
loadingSpeech = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let voices = [];
|
let voices = [];
|
||||||
|
Loading…
Reference in New Issue
Block a user