Stabilize playback state and cursor feedback

This commit is contained in:
2026-05-18 20:57:20 +02:00
parent 6e908037fb
commit 751ac5f62b
13 changed files with 580 additions and 82 deletions
+10 -1
View File
@@ -1224,9 +1224,11 @@ class TTSFactoryModule extends BaseModule {
return null;
}
let hash = null;
let generationStarted = false;
try {
// Generate a hash for this speech request
const hash = await this.generateSpeechHash(text);
hash = await this.generateSpeechHash(text);
// Check if we have this audio in cache
const cachedData = await this.getCachedSpeech(hash);
@@ -1242,6 +1244,7 @@ class TTSFactoryModule extends BaseModule {
// Cache miss - need to generate new speech data
this.cacheMisses++;
generationStarted = true;
this.emitProcessState('waiting-generating', { reason: 'tts-cache-miss', hash });
// If the handler has a preloadSpeech method, use it
@@ -1253,15 +1256,21 @@ class TTSFactoryModule extends BaseModule {
await this.cacheSpeech(hash, preloadData.audioData, preloadData.duration);
console.log(`TTS Factory: Added speech to cache for hash ${hash} (size: ${this.currentCacheSize}/${this.maxCacheSizeBytes})`);
this.emitProcessState('playing-ready', { reason: 'tts-generated', hash });
} else if (generationStarted) {
this.emitProcessState('playing-ready', { reason: 'tts-generation-unavailable', hash });
}
return preloadData;
} else {
console.warn(`TTS Factory: Handler ${this.activeHandler} does not support preloading`);
this.emitProcessState('playing-ready', { reason: 'tts-preload-unsupported', hash });
return null;
}
} catch (error) {
console.error("TTS Factory: Error preloading speech:", error);
if (generationStarted || hash) {
this.emitProcessState('playing-ready', { reason: 'tts-generation-error', hash, error });
}
return null;
}
}