Small tts fix
All checks were successful
Build and publish / Build Container (push) Successful in 1m26s

This commit is contained in:
2026-03-03 20:23:59 -05:00
parent 5018311990
commit 6c2c3a0d07
2 changed files with 9 additions and 16 deletions

View File

@@ -101,7 +101,7 @@ export class TTS {
} }
async speak(t) { async speak(t) {
if (!t.trim()) return; if(!t.trim()) return;
await this._voicesLoaded; await this._voicesLoaded;
if(this._currentUtterance && !this._isStreaming) this.stop(); if(this._currentUtterance && !this._isStreaming) this.stop();
return new Promise((res, rej) => { return new Promise((res, rej) => {
@@ -118,7 +118,8 @@ export class TTS {
else rej(e); else rej(e);
}; };
window.speechSynthesis.speak(u); window.speechSynthesis.speak(u);
}); this._emit('onSentenceStart', {sentence: t});
}).finally(() => this._emit('onSentenceEnd', {sentence: t}));
} }
stop() { stop() {
@@ -143,11 +144,7 @@ export class TTS {
if(ss) { if(ss) {
ss.forEach(s => { ss.forEach(s => {
const sentence = s.trim(); const sentence = s.trim();
sentenceQueue = sentenceQueue.then(async () => { sentenceQueue = sentenceQueue.then(async () => this.speak(sentence));
this._emit('onSentenceStart', { sentence });
await this.speak(sentence);
this._emit('onSentenceEnd', { sentence });
});
}); });
} }
buf = buf.replace(rx, ''); buf = buf.replace(rx, '');
@@ -155,11 +152,7 @@ export class TTS {
done: async () => { done: async () => {
if (buf.trim()) { if (buf.trim()) {
const sentence = buf.trim(); const sentence = buf.trim();
sentenceQueue = sentenceQueue.then(async () => { sentenceQueue = sentenceQueue.then(async () => this.speak(sentence));
this._emit('onSentenceStart', { sentence });
await this.speak(sentence);
this._emit('onSentenceEnd', { sentence });
});
buf = ''; buf = '';
} }
await sentenceQueue; await sentenceQueue;

View File

@@ -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)]} emote: {type: 'string', description: 'Emote to the user', required: true, enum: ['none', ...Object.keys(settings.animations.emote)]}
}, },
fn: (args, stream) => { fn: (args, stream) => {
if(!['none', ...Object.keys(settings.animations.emote)].includes(args.emote)) const exists = ['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(', ')}`) if(!exists) stream({emote: 'none'});
stream({emote: args.emote}); else stream({emote: args.emote});
return 'done!'; return exists ? 'done!' : `Invalid emote: ${args.emote}`;
} }
}, { }, {
name: 'personalize', name: 'personalize',