mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge pull request #3371 from fearmear/release
Decrease TTS generation delay by splitting a message on a new line
This commit is contained in:
@@ -120,7 +120,7 @@ async function onNarrateOneMessage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resetTtsPlayback();
|
resetTtsPlayback();
|
||||||
ttsJobQueue.push(message);
|
processAndQueueTtsMessage(message);
|
||||||
moduleWorker();
|
moduleWorker();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,7 +147,7 @@ async function onNarrateText(args, text) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resetTtsPlayback();
|
resetTtsPlayback();
|
||||||
ttsJobQueue.push({ mes: text, name: name });
|
processAndQueueTtsMessage({ mes: text, name: name });
|
||||||
await moduleWorker();
|
await moduleWorker();
|
||||||
|
|
||||||
// Return back to the chat voices
|
// Return back to the chat voices
|
||||||
@@ -220,6 +220,36 @@ function isTtsProcessing() {
|
|||||||
return processing;
|
return processing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Splits a message into lines and adds each non-empty line to the TTS job queue.
|
||||||
|
* @param {Object} message - The message object to be processed.
|
||||||
|
* @param {string} message.mes - The text of the message to be split into lines.
|
||||||
|
* @param {string} message.name - The name associated with the message.
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
function processAndQueueTtsMessage(message) {
|
||||||
|
if (!extension_settings.tts.narrate_by_paragraphs) {
|
||||||
|
ttsJobQueue.push(message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const lines = message.mes.split('\n');
|
||||||
|
|
||||||
|
for (let i = 0; i < lines.length; i++) {
|
||||||
|
const line = lines[i];
|
||||||
|
|
||||||
|
if (line.length === 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ttsJobQueue.push(
|
||||||
|
Object.assign({}, message, {
|
||||||
|
mes: line,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function debugTtsPlayback() {
|
function debugTtsPlayback() {
|
||||||
console.log(JSON.stringify(
|
console.log(JSON.stringify(
|
||||||
{
|
{
|
||||||
@@ -350,7 +380,7 @@ function onAudioControlClicked() {
|
|||||||
talkingAnimation(false);
|
talkingAnimation(false);
|
||||||
} else {
|
} else {
|
||||||
// Default play behavior if not processing or playing is to play the last message.
|
// Default play behavior if not processing or playing is to play the last message.
|
||||||
ttsJobQueue.push(context.chat[context.chat.length - 1]);
|
processAndQueueTtsMessage(context.chat[context.chat.length - 1]);
|
||||||
}
|
}
|
||||||
updateUiAudioPlayState();
|
updateUiAudioPlayState();
|
||||||
}
|
}
|
||||||
@@ -569,6 +599,7 @@ function loadSettings() {
|
|||||||
$('#tts_narrate_quoted').prop('checked', extension_settings.tts.narrate_quoted_only);
|
$('#tts_narrate_quoted').prop('checked', extension_settings.tts.narrate_quoted_only);
|
||||||
$('#tts_auto_generation').prop('checked', extension_settings.tts.auto_generation);
|
$('#tts_auto_generation').prop('checked', extension_settings.tts.auto_generation);
|
||||||
$('#tts_periodic_auto_generation').prop('checked', extension_settings.tts.periodic_auto_generation);
|
$('#tts_periodic_auto_generation').prop('checked', extension_settings.tts.periodic_auto_generation);
|
||||||
|
$('#tts_narrate_by_paragraphs').prop('checked', extension_settings.tts.narrate_by_paragraphs);
|
||||||
$('#tts_narrate_translated_only').prop('checked', extension_settings.tts.narrate_translated_only);
|
$('#tts_narrate_translated_only').prop('checked', extension_settings.tts.narrate_translated_only);
|
||||||
$('#tts_narrate_user').prop('checked', extension_settings.tts.narrate_user);
|
$('#tts_narrate_user').prop('checked', extension_settings.tts.narrate_user);
|
||||||
$('#tts_pass_asterisks').prop('checked', extension_settings.tts.pass_asterisks);
|
$('#tts_pass_asterisks').prop('checked', extension_settings.tts.pass_asterisks);
|
||||||
@@ -638,6 +669,11 @@ function onPeriodicAutoGenerationClick() {
|
|||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onNarrateByParagraphsClick() {
|
||||||
|
extension_settings.tts.narrate_by_paragraphs = !!$('#tts_narrate_by_paragraphs').prop('checked');
|
||||||
|
saveSettingsDebounced();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function onNarrateDialoguesClick() {
|
function onNarrateDialoguesClick() {
|
||||||
extension_settings.tts.narrate_dialogues_only = !!$('#tts_narrate_dialogues').prop('checked');
|
extension_settings.tts.narrate_dialogues_only = !!$('#tts_narrate_dialogues').prop('checked');
|
||||||
@@ -816,7 +852,12 @@ async function onMessageEvent(messageId, lastCharIndex) {
|
|||||||
lastChatId = context.chatId;
|
lastChatId = context.chatId;
|
||||||
|
|
||||||
console.debug(`Adding message from ${message.name} for TTS processing: "${message.mes}"`);
|
console.debug(`Adding message from ${message.name} for TTS processing: "${message.mes}"`);
|
||||||
ttsJobQueue.push(message);
|
|
||||||
|
if (extension_settings.tts.periodic_auto_generation) {
|
||||||
|
ttsJobQueue.push(message);
|
||||||
|
} else {
|
||||||
|
processAndQueueTtsMessage(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onMessageDeleted() {
|
async function onMessageDeleted() {
|
||||||
@@ -1156,6 +1197,7 @@ jQuery(async function () {
|
|||||||
$('#tts_pass_asterisks').on('click', onPassAsterisksClick);
|
$('#tts_pass_asterisks').on('click', onPassAsterisksClick);
|
||||||
$('#tts_auto_generation').on('click', onAutoGenerationClick);
|
$('#tts_auto_generation').on('click', onAutoGenerationClick);
|
||||||
$('#tts_periodic_auto_generation').on('click', onPeriodicAutoGenerationClick);
|
$('#tts_periodic_auto_generation').on('click', onPeriodicAutoGenerationClick);
|
||||||
|
$('#tts_narrate_by_paragraphs').on('click', onNarrateByParagraphsClick);
|
||||||
$('#tts_narrate_user').on('click', onNarrateUserClick);
|
$('#tts_narrate_user').on('click', onNarrateUserClick);
|
||||||
|
|
||||||
$('#playback_rate').on('input', function () {
|
$('#playback_rate').on('input', function () {
|
||||||
|
@@ -30,6 +30,10 @@
|
|||||||
<input type="checkbox" id="tts_periodic_auto_generation">
|
<input type="checkbox" id="tts_periodic_auto_generation">
|
||||||
<small data-i18n="Narrate by paragraphs (when streaming)">Narrate by paragraphs (when streaming)</small>
|
<small data-i18n="Narrate by paragraphs (when streaming)">Narrate by paragraphs (when streaming)</small>
|
||||||
</label>
|
</label>
|
||||||
|
<label class="checkbox_label" for="tts_narrate_by_paragraphs">
|
||||||
|
<input type="checkbox" id="tts_narrate_by_paragraphs">
|
||||||
|
<small data-i18n="Narrate by paragraphs (when not streaming)">Narrate by paragraphs (when not streaming)</small>
|
||||||
|
</label>
|
||||||
<label class="checkbox_label" for="tts_narrate_quoted">
|
<label class="checkbox_label" for="tts_narrate_quoted">
|
||||||
<input type="checkbox" id="tts_narrate_quoted">
|
<input type="checkbox" id="tts_narrate_quoted">
|
||||||
<small data-i18n="Only narrate quotes">Only narrate "quotes"</small>
|
<small data-i18n="Only narrate quotes">Only narrate "quotes"</small>
|
||||||
|
Reference in New Issue
Block a user