add fix for template response
This commit is contained in:
parent
99d7950afd
commit
47b15a6318
@ -86,21 +86,36 @@ async function getDonatInfo(streamerID) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function playAudio(url, callback, volume) {
|
||||||
|
const audio = new Audio(url);
|
||||||
|
audio.volume = volume;
|
||||||
|
audio.play().then(() => {
|
||||||
|
audio.addEventListener('ended', callback);
|
||||||
|
}).catch(error => {
|
||||||
|
console.error('Error playing audio:', error);
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function playSpeech(text, voiceSettings) {
|
function playSpeech(text, voiceSettings) {
|
||||||
if (!voiceSettings.voice_enabled) return;
|
if (!voiceSettings.voice_enabled) return;
|
||||||
|
|
||||||
const params = new URLSearchParams({
|
const requestBody = {
|
||||||
text: text,
|
text: text,
|
||||||
speed: voiceSettings.voice_speed || 'medium',
|
speed: (voiceSettings.voice_speed || 'medium').toLowerCase(),
|
||||||
scenery: voiceSettings.scenery || 'default',
|
scenery: voiceSettings.scenery || 'default',
|
||||||
sound_percent: voiceSettings.voice_sound_percent || 100,
|
sound_percent: voiceSettings.voice_sound_percent || 100,
|
||||||
min_price: voiceSettings.min_price || 0,
|
min_price: voiceSettings.min_price || 0,
|
||||||
languages: voiceSettings.languages?.join(',') || ''
|
languages: voiceSettings.languages || ['ru']
|
||||||
});
|
};
|
||||||
|
|
||||||
const url = ttsUrl + '/generate?' + params.toString();
|
fetch(ttsUrl + '/generate', {
|
||||||
|
method: 'POST',
|
||||||
fetch(url)
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(requestBody)
|
||||||
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (!response.ok) throw new Error('TTS error');
|
if (!response.ok) throw new Error('TTS error');
|
||||||
return response.blob();
|
return response.blob();
|
||||||
@ -108,6 +123,7 @@ function playSpeech(text, voiceSettings) {
|
|||||||
.then(blob => {
|
.then(blob => {
|
||||||
const url = URL.createObjectURL(blob);
|
const url = URL.createObjectURL(blob);
|
||||||
const audio = new Audio(url);
|
const audio = new Audio(url);
|
||||||
|
audio.volume = (voiceSettings.voice_sound_percent || 100) / 100;
|
||||||
audio.play().catch(console.error);
|
audio.play().catch(console.error);
|
||||||
audio.addEventListener('ended', () => {
|
audio.addEventListener('ended', () => {
|
||||||
URL.revokeObjectURL(url);
|
URL.revokeObjectURL(url);
|
||||||
@ -117,7 +133,30 @@ function playSpeech(text, voiceSettings) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function playSpeechAfterAudio(audioUrl, text, voiceSettings) {
|
function playSpeechAfterAudio(audioUrl, text, voiceSettings) {
|
||||||
playAudio(audioUrl, () => playSpeech(text, voiceSettings));
|
const volume = (voiceSettings.voice_sound_percent || 100) / 100;
|
||||||
|
playAudio(audioUrl, () => playSpeech(text, voiceSettings), volume);
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearContainer(container) {
|
||||||
|
while (container.firstChild) {
|
||||||
|
container.removeChild(container.firstChild);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function addImage(container, imageUrl) {
|
||||||
|
const img = document.createElement('img');
|
||||||
|
img.src = imageUrl;
|
||||||
|
container.appendChild(img);
|
||||||
|
}
|
||||||
|
|
||||||
|
function createTextElement(text) {
|
||||||
|
const container = document.createElement('div');
|
||||||
|
container.className = 'text-container';
|
||||||
|
const textElem = document.createElement('p');
|
||||||
|
textElem.className = 'donation-text';
|
||||||
|
textElem.textContent = text;
|
||||||
|
container.appendChild(textElem);
|
||||||
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function widgetView() {
|
async function widgetView() {
|
||||||
@ -156,7 +195,7 @@ async function widgetView() {
|
|||||||
contentDiv.appendChild(textElement);
|
contentDiv.appendChild(textElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Воспроизведение аудио и TTS
|
// Настройки голоса и громкости
|
||||||
const voiceSettings = {
|
const voiceSettings = {
|
||||||
voice_speed: donat.voice_speed,
|
voice_speed: donat.voice_speed,
|
||||||
scenery: donat.scenery,
|
scenery: donat.scenery,
|
||||||
@ -166,6 +205,7 @@ async function widgetView() {
|
|||||||
voice_enabled: donat.voice_enabled
|
voice_enabled: donat.voice_enabled
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Воспроизведение аудио и TTS
|
||||||
if (donat.audio_link) {
|
if (donat.audio_link) {
|
||||||
playSpeechAfterAudio(donat.audio_link, donat.text, voiceSettings);
|
playSpeechAfterAudio(donat.audio_link, donat.text, voiceSettings);
|
||||||
} else if (donat.text && donat.voice_enabled) {
|
} else if (donat.text && donat.voice_enabled) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user