From ab52c5227e349716af6cb59066416510d09cdefd Mon Sep 17 00:00:00 2001 From: mm Date: Wed, 30 Oct 2024 01:59:46 +0500 Subject: [PATCH] dev --- internal/model/widget-templates.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) 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) {