From 6c2c3a0d07dbc0ba968271c0c8c496992e3ab3a4 Mon Sep 17 00:00:00 2001 From: ztimson Date: Tue, 3 Mar 2026 20:23:59 -0500 Subject: [PATCH] Small tts fix --- public/tts.mjs | 17 +++++------------ src/server.js | 8 ++++---- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/public/tts.mjs b/public/tts.mjs index 19b2658..4d13b25 100644 --- a/public/tts.mjs +++ b/public/tts.mjs @@ -101,7 +101,7 @@ export class TTS { } async speak(t) { - if (!t.trim()) return; + if(!t.trim()) return; await this._voicesLoaded; if(this._currentUtterance && !this._isStreaming) this.stop(); return new Promise((res, rej) => { @@ -118,7 +118,8 @@ export class TTS { else rej(e); }; window.speechSynthesis.speak(u); - }); + this._emit('onSentenceStart', {sentence: t}); + }).finally(() => this._emit('onSentenceEnd', {sentence: t})); } stop() { @@ -143,11 +144,7 @@ export class TTS { if(ss) { ss.forEach(s => { const sentence = s.trim(); - sentenceQueue = sentenceQueue.then(async () => { - this._emit('onSentenceStart', { sentence }); - await this.speak(sentence); - this._emit('onSentenceEnd', { sentence }); - }); + sentenceQueue = sentenceQueue.then(async () => this.speak(sentence)); }); } buf = buf.replace(rx, ''); @@ -155,11 +152,7 @@ export class TTS { done: async () => { if (buf.trim()) { const sentence = buf.trim(); - sentenceQueue = sentenceQueue.then(async () => { - this._emit('onSentenceStart', { sentence }); - await this.speak(sentence); - this._emit('onSentenceEnd', { sentence }); - }); + sentenceQueue = sentenceQueue.then(async () => this.speak(sentence)); buf = ''; } await sentenceQueue; diff --git a/src/server.js b/src/server.js index 38a959d..4e734ac 100644 --- a/src/server.js +++ b/src/server.js @@ -107,10 +107,10 @@ const ai = new Ai({ emote: {type: 'string', description: 'Emote to the user', required: true, enum: ['none', ...Object.keys(settings.animations.emote)]} }, fn: (args, stream) => { - if(!['none', ...Object.keys(settings.animations.emote)].includes(args.emote)) - throw new Error(`Invalid emote, must be one of: ${['none', ...Object.keys(settings.animations.emote)].join(', ')}`) - stream({emote: args.emote}); - return 'done!'; + const exists = ['none', ...Object.keys(settings.animations.emote)].includes(args.emote); + if(!exists) stream({emote: 'none'}); + else stream({emote: args.emote}); + return exists ? 'done!' : `Invalid emote: ${args.emote}`; } }, { name: 'personalize',