diff --git a/internal/model/widget-templates.go b/internal/model/widget-templates.go index e7ce977..867f349 100644 --- a/internal/model/widget-templates.go +++ b/internal/model/widget-templates.go @@ -77,13 +77,25 @@ async function playAudio(audioUrl) { } function playSpeech(text) { - const audio = new Audio(ttsUrl + '/generate', { + audioUrl = fetch(ttsUrl + '/generate', { method: 'POST', body: JSON.stringify({ text: text, }), - }); - audio.play() + }).then( + response => { + const audioUrl = URL.createObjectURL(blob); + const audio = new Audio(audioUrl); + audio.play().catch(error => { + console.error('Ошибка при воспроизведении:', error); + }); + + audio.addEventListener('ended', () => { + URL.revokeObjectURL(audioUrl); + console.log('Аудио закончилось и временный URL удален.'); + }); + } + ) } function delay(ms) {