TTS plugin adjustments

This commit is contained in:
SillyLossy
2023-05-05 18:14:33 +03:00
parent f9d3120338
commit 99b2f499d3
2 changed files with 10 additions and 4 deletions

View File

@ -1,5 +1,6 @@
import { callPopup, saveSettingsDebounced } from '../../../script.js' import { callPopup, is_send_press, saveSettingsDebounced } from '../../../script.js'
import { extension_settings, getContext } from '../../extensions.js' import { extension_settings, getContext } from '../../extensions.js'
import { is_group_generating } from '../../group-chats.js'
import { getStringHash } from '../../utils.js' import { getStringHash } from '../../utils.js'
import { ElevenLabsTtsProvider } from './elevenlabs.js' import { ElevenLabsTtsProvider } from './elevenlabs.js'
import { SileroTtsProvider } from './silerotts.js' import { SileroTtsProvider } from './silerotts.js'
@ -43,6 +44,11 @@ async function moduleWorker() {
return return
} }
// Message is currently being generated
if (is_send_press || is_group_generating) {
return;
}
// Chat/character/group changed // Chat/character/group changed
if ( if (
(context.groupId && lastGroupId !== context.groupId) || (context.groupId && lastGroupId !== context.groupId) ||
@ -115,7 +121,7 @@ async function playAudioData(audioBlob) {
window['tts_preview'] = function (id) { window['tts_preview'] = function (id) {
const audio = document.getElementById(id) const audio = document.getElementById(id)
if (!audio.hidden) { if (!$(audio).data('disabled')) {
audio.play() audio.play()
} }
else { else {
@ -131,7 +137,7 @@ async function onTtsVoicesClick() {
for (const voice of voiceIds) { for (const voice of voiceIds) {
popupText += `<div class="voice_preview"><span class="voice_lang">${voice.lang || ''}</span> <b class="voice_name">${voice.name}</b> <i onclick="tts_preview('${voice.voice_id}')" class="fa-solid fa-play"></i></div>` popupText += `<div class="voice_preview"><span class="voice_lang">${voice.lang || ''}</span> <b class="voice_name">${voice.name}</b> <i onclick="tts_preview('${voice.voice_id}')" class="fa-solid fa-play"></i></div>`
popupText += `<audio id="${voice.voice_id}" src="${voice.preview_url}" hidden="${!!voice.preview_url}"></audio>` popupText += `<audio id="${voice.voice_id}" src="${voice.preview_url}" data-disabled="${voice.preview_url == false}"></audio>`
} }
} catch { } catch {
popupText = 'Could not load voices list. Check your API key.' popupText = 'Could not load voices list. Check your API key.'

View File

@ -87,7 +87,7 @@ class SystemTtsProvider {
return speechSynthesis return speechSynthesis
.getVoices() .getVoices()
.sort((a, b) => a.lang.localeCompare(b.lang) || a.name.localeCompare(b.name)) .sort((a, b) => a.lang.localeCompare(b.lang) || a.name.localeCompare(b.name))
.map(x => ({ name: x.name, voice_id: x.voiceURI, preview_url: '', lang: x.lang })); .map(x => ({ name: x.name, voice_id: x.voiceURI, preview_url: false, lang: x.lang }));
} }
previewTtsVoice(voiceId) { previewTtsVoice(voiceId) {