mirror of
				https://github.com/SillyTavern/SillyTavern.git
				synced 2025-06-05 21:59:27 +02:00 
			
		
		
		
	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); |     splitMessageAndAddToTtsJobQueue(message); | ||||||
|     moduleWorker(); |     moduleWorker(); | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -147,7 +147,7 @@ async function onNarrateText(args, text) { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     resetTtsPlayback(); |     resetTtsPlayback(); | ||||||
|     ttsJobQueue.push({ mes: text, name: name }); |     splitMessageAndAddToTtsJobQueue({ mes: text, name: name }); | ||||||
|     await moduleWorker(); |     await moduleWorker(); | ||||||
|  |  | ||||||
|     // Return back to the chat voices |     // Return back to the chat voices | ||||||
| @@ -220,6 +220,31 @@ 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 splitMessageAndAddToTtsJobQueue(message) { | ||||||
|  |     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 +375,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]); |         splitMessageAndAddToTtsJobQueue(context.chat[context.chat.length - 1]); | ||||||
|     } |     } | ||||||
|     updateUiAudioPlayState(); |     updateUiAudioPlayState(); | ||||||
| } | } | ||||||
| @@ -816,7 +841,7 @@ 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); |     splitMessageAndAddToTtsJobQueue(message); | ||||||
| } | } | ||||||
|  |  | ||||||
| async function onMessageDeleted() { | async function onMessageDeleted() { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user