mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-01-23 07:51:18 +01:00
fix tts re-trigger for complete/autocomplete/delete
fix re-trigger tts from start if text was added to chat by auto-continue fix re-trigger tts from start if text was added by continue button fix re-trigger of tts when message(s) got deleted
This commit is contained in:
parent
064d331110
commit
91266c831c
@ -76,6 +76,8 @@ let ttsProviders = {
|
|||||||
let ttsProvider
|
let ttsProvider
|
||||||
let ttsProviderName
|
let ttsProviderName
|
||||||
|
|
||||||
|
let ttsLastMessage = null;
|
||||||
|
|
||||||
async function onNarrateOneMessage() {
|
async function onNarrateOneMessage() {
|
||||||
audioElement.src = '/sounds/silence.mp3';
|
audioElement.src = '/sounds/silence.mp3';
|
||||||
const context = getContext();
|
const context = getContext();
|
||||||
@ -132,11 +134,27 @@ async function moduleWorker() {
|
|||||||
let diff = lastMessageNumber - currentMessageNumber
|
let diff = lastMessageNumber - currentMessageNumber
|
||||||
let hashNew = getStringHash((chat.length && chat[chat.length - 1].mes) ?? '')
|
let hashNew = getStringHash((chat.length && chat[chat.length - 1].mes) ?? '')
|
||||||
|
|
||||||
|
// if messages got deleted, diff will be < 0
|
||||||
|
if (diff < 0) {
|
||||||
|
// necessary actions will be taken by the onChatDeleted() handler
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (diff == 0 && hashNew === lastMessageHash) {
|
if (diff == 0 && hashNew === lastMessageHash) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const message = chat[chat.length - 1]
|
// clone message object, as things go haywire if message object is altered below (it's passed by reference)
|
||||||
|
const message = JSON.parse(JSON.stringify(chat[chat.length - 1]))
|
||||||
|
|
||||||
|
// if last message within current message, message got extended. only send diff to TTS.
|
||||||
|
if (ttsLastMessage !== null && message.mes.indexOf(ttsLastMessage) !== -1) {
|
||||||
|
let tmp = message.mes
|
||||||
|
message.mes = message.mes.replace(ttsLastMessage, '')
|
||||||
|
ttsLastMessage = tmp
|
||||||
|
} else {
|
||||||
|
ttsLastMessage = message.mes
|
||||||
|
}
|
||||||
|
|
||||||
// We're currently swiping or streaming. Don't generate voice
|
// We're currently swiping or streaming. Don't generate voice
|
||||||
if (
|
if (
|
||||||
@ -630,6 +648,25 @@ async function onChatChanged() {
|
|||||||
await initVoiceMap()
|
await initVoiceMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function onChatDeleted() {
|
||||||
|
const context = getContext()
|
||||||
|
|
||||||
|
// update internal references to new last message
|
||||||
|
lastChatId = context.chatId
|
||||||
|
currentMessageNumber = context.chat.length ? context.chat.length : 0
|
||||||
|
|
||||||
|
// compare against lastMessageHash. If it's the same, we did not delete the last chat item, so no need to reset tts queue
|
||||||
|
let messageHash = getStringHash((context.chat.length && context.chat[context.chat.length - 1].mes) ?? '')
|
||||||
|
if (messageHash === lastMessageHash) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
lastMessageHash = messageHash
|
||||||
|
ttsLastMessage = (context.chat.length && context.chat[context.chat.length - 1].mes) ?? '';
|
||||||
|
|
||||||
|
// stop any tts playback since message might not exist anymore
|
||||||
|
await resetTtsPlayback()
|
||||||
|
}
|
||||||
|
|
||||||
function getCharacters(){
|
function getCharacters(){
|
||||||
const context = getContext()
|
const context = getContext()
|
||||||
let characters = []
|
let characters = []
|
||||||
@ -771,7 +808,7 @@ export async function initVoiceMap(){
|
|||||||
// Clear existing voiceMap state
|
// Clear existing voiceMap state
|
||||||
$('#tts_voicemap_block').empty()
|
$('#tts_voicemap_block').empty()
|
||||||
voiceMapEntries = []
|
voiceMapEntries = []
|
||||||
|
|
||||||
// Get characters in current chat
|
// Get characters in current chat
|
||||||
const characters = getCharacters()
|
const characters = getCharacters()
|
||||||
|
|
||||||
@ -898,4 +935,5 @@ $(document).ready(function () {
|
|||||||
eventSource.on(event_types.MESSAGE_SWIPED, resetTtsPlayback);
|
eventSource.on(event_types.MESSAGE_SWIPED, resetTtsPlayback);
|
||||||
eventSource.on(event_types.CHAT_CHANGED, onChatChanged)
|
eventSource.on(event_types.CHAT_CHANGED, onChatChanged)
|
||||||
eventSource.on(event_types.GROUP_UPDATED, onChatChanged)
|
eventSource.on(event_types.GROUP_UPDATED, onChatChanged)
|
||||||
|
eventSource.on(event_types.MESSAGE_DELETED, onChatDeleted);
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user