6.4 KiB
6.4 KiB
Client Architecture Refactoring TODO List
Phase 1: Cleanup and Removal of Redundant Components
High Priority Removals
-
TTSPlayerModule - Complete Removal
- Mark entire module for removal (completely redundant with SentenceQueueModule)
- Identify all references to TTSPlayerModule across the codebase
- Plan migration path for any UI components directly using TTSPlayerModule
- Update any event listeners that expect TTSPlayerModule events
-
UIDisplayHandlerModule Cleanup
- Remove
pendingParagraphsqueue - Remove
processNextParagraph()method - Refactor
displayText()to be a thin wrapper for SentenceQueue
- Remove
-
KokoroTTSModule Cleanup
- Remove
pendingGenerationsMap - Refactor
generateSpeech()to work directly with SentenceQueue - Update iframe message handling to support the new architecture
- Remove
-
LayoutRendererModule Cleanup
- Remove TTS triggering from
renderParagraph()method - Remove animation scheduling from rendering logic
- Separate layout rendering from animation timing
- Remove TTS triggering from
Additional Obsolete Components
-
TextBufferModule Redundancies
- Remove sentence preparation logic that will move to SentenceQueue
- Remove any temporary sentence storage mechanisms
- Identify and mark for removal any text processing that duplicates SentenceQueue functionality
-
AnimationQueueModule Overlaps
- Identify animation scheduling that will be handled by SentenceQueue
- Remove redundant animation timing calculations
- Refactor to work as a service for SentenceQueue
-
TTSFactoryModule Redundancies
- Remove any temporary audio storage that duplicates SentenceQueue functionality
- Refactor speech generation methods to work with SentenceQueue
- Streamline caching to avoid duplication with SentenceQueue
-
Event System Cleanup
- Identify and remove redundant TTS-related events
- Remove text animation events that will be handled by SentenceQueue
- Consolidate playback state events
Phase 2: Enhanced SentenceQueueModule Implementation
Core Structure and Design
-
Design the Sentence Object Structure
- Define comprehensive sentence object with fields for:
- Unique ID
- Original text
- Processed text (hyphenated, typeset)
- Layout information (breaks, nodes, typography)
- Audio component (player, duration, data, type)
- Status tracking (pending, processing, ready, playing, complete)
- Define comprehensive sentence object with fields for:
-
Implement Basic Queue Management
- Create methods for adding sentences to the queue
- Implement queue processing logic that maintains order
- Add status tracking for each sentence in the queue
- Implement priority handling for urgent sentences
Text Processing Integration
-
Integrate with Paragraph Layout
- Connect to ParagraphLayoutModule for text processing
- Implement hyphenation and typesetting in the queue
- Store layout information in the sentence object
- Ensure layout processing happens in parallel with audio
-
Text Animation Preparation
- Calculate animation timing based on text length and settings
- Prepare animation data for each word in the sentence
- Store animation timing in the sentence object
- Create animation player function for the sentence
Audio Processing Integration
-
TTS System Integration
- Implement audio generation for Kokoro TTS
- Implement browser TTS handling with duration estimation
- Implement "none" TTS option with duration calculation
- Create consistent player interface for all TTS types
-
Audio Data Management
- Implement audio data storage in sentence objects
- Connect with TTSFactoryModule's IndexedDB for persistent caching
- Add audio preloading capabilities
- Implement audio resource cleanup
Playback Coordination
-
Synchronized Playback
- Implement coordinated text animation and audio playback
- Create timing adjustment based on speed settings
- Add event handling for playback states (start, pause, resume, complete)
- Implement sentence transition handling
-
User Interaction Handling
- Add support for fast-forwarding text/audio
- Implement pause/resume functionality
- Handle user interruptions gracefully
- Support skipping to next sentence
Phase 3: Module Interface Updates
-
Update Module Interfaces
- Create consistent interfaces for interacting with SentenceQueue
- Update event system to work with sentence objects
- Implement progress reporting for sentence processing
- Add debugging and monitoring capabilities
-
Documentation and Examples
- Document the new architecture and interfaces
- Create usage examples for common scenarios
- Update developer guidelines
- Add migration guide for existing code
Phase 4: Testing and Validation
-
Unit Testing
- Create tests for SentenceQueue core functionality
- Test text processing integration
- Test audio processing integration
- Test playback coordination
-
Integration Testing
- Test interaction between SentenceQueue and other modules
- Validate timing and synchronization
- Test error handling and recovery
- Verify performance under load
-
User Experience Testing
- Validate text animation quality
- Test audio playback quality
- Verify synchronization from user perspective
- Test accessibility features
Implementation Strategy
-
Phased Rollout
- Complete cleanup of redundant components
- Implement SentenceQueue core structure
- Add text processing integration
- Add audio processing integration
- Implement playback coordination
- Gradually replace existing components
-
Backward Compatibility
- Maintain support for existing interfaces during transition
- Implement adapter patterns where needed
- Add feature flags for enabling/disabling new architecture
- Create fallback mechanisms for error recovery
-
Performance Optimization
- Implement parallel processing where possible
- Optimize memory usage for sentence objects
- Add resource management for audio data
- Implement efficient queue processing algorithms