Fixed kokoro loading process.
This commit is contained in:
@@ -676,9 +676,9 @@ class TTSFactoryModule extends BaseModule {
|
||||
* Speak text using the active TTS handler
|
||||
* @param {string} text - Text to speak
|
||||
* @param {Object} options - TTS options
|
||||
* @returns {boolean} - Success status
|
||||
* @returns {Promise<boolean>} - Success status
|
||||
*/
|
||||
speak(text, options = {}) {
|
||||
async speak(text, options = {}) {
|
||||
// Check if we have an active handler
|
||||
if (!this.activeHandler) {
|
||||
console.warn('TTS Factory: No active handler set');
|
||||
@@ -705,7 +705,39 @@ class TTSFactoryModule extends BaseModule {
|
||||
effectiveOptions.speed = this.speed;
|
||||
}
|
||||
|
||||
// Call the handler's speak method
|
||||
// Check if we have this speech cached
|
||||
const hash = await this.generateSpeechHash(text);
|
||||
const cached = await this.getCachedSpeech(hash);
|
||||
|
||||
if (cached && cached.success) {
|
||||
console.log(`TTS Factory: Using cached speech for hash ${hash}`);
|
||||
// Use cached speech
|
||||
return handler.speakPreloaded(cached, result => {
|
||||
document.dispatchEvent(new CustomEvent('tts:speechCompleted', {
|
||||
detail: { success: result?.success === true, error: result?.error }
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
// Not cached, generate and cache
|
||||
if (typeof handler.preloadSpeech === 'function') {
|
||||
console.log(`TTS Factory: Generating and caching speech for hash ${hash}`);
|
||||
const preloadData = await handler.preloadSpeech(text);
|
||||
if (preloadData && preloadData.success) {
|
||||
// Cache the speech
|
||||
await this.cacheSpeech(hash, preloadData);
|
||||
|
||||
// Speak the preloaded speech
|
||||
return handler.speakPreloaded(preloadData, result => {
|
||||
document.dispatchEvent(new CustomEvent('tts:speechCompleted', {
|
||||
detail: { success: result?.success === true, error: result?.error }
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to direct speak if preloading failed or not supported
|
||||
console.log(`TTS Factory: Falling back to direct speak (no caching)`);
|
||||
return handler.speak(text, result => {
|
||||
// Forward speech completion event
|
||||
document.dispatchEvent(new CustomEvent('tts:speechCompleted', {
|
||||
|
||||
Reference in New Issue
Block a user