This commit is contained in:
mm 2024-10-30 10:21:29 +05:00
parent 8caa75e388
commit 90677847f1

View File

@ -88,19 +88,26 @@ function playSpeech(text) {
body: JSON.stringify({ body: JSON.stringify({
text: text, text: text,
}), }),
}).then( })
response => { .then(response => {
audio = document.createElement('audio'); if (!response.ok) {
audio.src = response.blob(); throw new Error('Ошибка сети: ' + response.statusText);
audio.play().catch(error => { }
console.error('Ошибка при воспроизведении:', error); return response.blob();
}); })
.then(response => {
const url = URL.createObjectURL(blob);
const audio = new Audio(url);
audio.addEventListener('ended', () => { audio.play().catch(error => {
audio.pause(); console.error('Ошибка при воспроизведении:', error);
audio.remove(); });
console.log('Аудио закончилось и временный URL удален.');
}); audio.addEventListener('ended', () => {
audio.pause();
audio.remove();
console.log('Аудио закончилось и временный URL удален.');
});
} }
) )
} }