Class: AnimationToTTS

Inherits:
Object show all
Defined in:
lib/parse_animation_to_tts.rb

Instance Method Summary collapse

Constructor Details

#initialize(input_files = ARGV, options = {}) ⇒ AnimationToTTS

REQUIREMENTS: Parse animation specs and generate TTS YAML SEMANTIC TOKENS: CLASS_DEFINITION, INITIALIZATION, CONFIGURATION ARCHITECTURE: Main class for parsing and YAML generation IMPLEMENTATION: Core class with initialization and configuration TEST: Test class instantiation and configuration CROSS-REFERENCE: See REQUIREMENTS UPDATE for parsing requirements CROSS-REFERENCE: See SEMANTIC TOKENS UPDATE for class-related tokens CROSS-REFERENCE: See ARCHITECTURE UPDATE for class architecture CROSS-REFERENCE: See IMPLEMENTATION UPDATE for class implementation CROSS-REFERENCE: See TEST UPDATES NEEDED for class testing CROSS-REFERENCE: See CODE UPDATES for class code changes



561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
# File 'lib/parse_animation_to_tts.rb', line 561

def initialize(input_files = ARGV, options = {})
  # REQUIREMENTS: Accept multiple input files as parameters
  # SEMANTIC TOKENS: PARAMETER_PROC, FILE_LIST, INITIALIZATION
  # ARCHITECTURE: Initialize with file list and configuration
  # IMPLEMENTATION: Store input files and initialize data structures
  # TEST: Test initialization with various file lists
  # CROSS-REFERENCE: See REQUIREMENTS UPDATE for multiple file support
  # CROSS-REFERENCE: See SEMANTIC TOKENS UPDATE for ARGV processing
  # CROSS-REFERENCE: See ARCHITECTURE UPDATE for initialization architecture
  # CROSS-REFERENCE: See IMPLEMENTATION UPDATE for initialization implementation
  # CROSS-REFERENCE: See TEST UPDATES NEEDED for initialization testing
  # CROSS-REFERENCE: See CODE UPDATES for initialization code changes
  
  @input_files = input_files
  @quiet_mode = options[:quiet] || false
  @segments = []
  @gaps = []
  @index = 0
  @total_duration = 0.0
  @metadata = {
    'generated_at' => Time.now.iso8601,
    'source_files' => [],
    'total_duration' => 0.0,
    'segment_count' => 0,
    'gap_count' => 0
  }
  
  # REQUIREMENTS: Validate input files exist and are readable
  # SEMANTIC TOKENS: VALIDATION, ERROR_HANDLING, FILE_EXISTENCE
  # ARCHITECTURE: Input validation layer before processing
  # IMPLEMENTATION: Check file existence and permissions
  # TEST: Test with missing files, invalid files, permission issues
  
  validate_input_files
end

Instance Method Details

#generate_yamlObject



660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
# File 'lib/parse_animation_to_tts.rb', line 660

def generate_yaml
  # REQUIREMENTS: Generate YAML output with audio segments and timing
  # SEMANTIC TOKENS: YAML_GEN, OUTPUT_FORMATTING, DATA_STRUCTURE
  # ARCHITECTURE: YAML generation with proper structure
  # IMPLEMENTATION: Create YAML with segments, gaps, and metadata
  # TEST: Test YAML output format and structure validation
  # CROSS-REFERENCE: See REQUIREMENTS UPDATE for YAML generation requirements
  # CROSS-REFERENCE: See SEMANTIC TOKENS UPDATE for YAML structure tokens
  # CROSS-REFERENCE: See ARCHITECTURE UPDATE for YAML generation architecture
  # CROSS-REFERENCE: See IMPLEMENTATION UPDATE for YAML generation implementation
  # CROSS-REFERENCE: See TEST UPDATES NEEDED for YAML testing
  # CROSS-REFERENCE: See CODE UPDATES for YAML generation code changes
  
  yaml_data = {
    'metadata' => @metadata,
    'audio_segments' => @segments,
    'gaps' => @gaps
  }
  
  # REQUIREMENTS: Output YAML to stdout for pipeline processing
  # SEMANTIC TOKENS: OUTPUT_STREAM, YAML_SERIALIZATION, PIPELINE_INTEGRATION
  # ARCHITECTURE: Standard output for pipeline integration
  # IMPLEMENTATION: Generate and output YAML to stdout
  # TEST: Test YAML output format and pipeline integration
  
  yaml_output = yaml_data.to_yaml
  puts yaml_output
  yaml_output
end

#parseObject



597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
# File 'lib/parse_animation_to_tts.rb', line 597

def parse
  # REQUIREMENTS: Parse each input file and extract TEXT specifications
  # SEMANTIC TOKENS: FILE_PROCESSING, TEXT_EXTRACT, TIMING_PARSING
  # ARCHITECTURE: Main parsing loop with file iteration
  # IMPLEMENTATION: Process each file and extract text segments
  # TEST: Test parsing with various file formats and content
  # CROSS-REFERENCE: See REQUIREMENTS UPDATE for parsing requirements
  # CROSS-REFERENCE: See SEMANTIC TOKENS UPDATE for parsing tokens
  # CROSS-REFERENCE: See ARCHITECTURE UPDATE for parsing architecture
  # CROSS-REFERENCE: See IMPLEMENTATION UPDATE for parsing implementation
  # CROSS-REFERENCE: See TEST UPDATES NEEDED for parsing testing
  # CROSS-REFERENCE: See CODE UPDATES for parsing code changes
  
  puts "# INFO: Starting parsing of #{@input_files.length} file(s)" unless @quiet_mode
  
  # Check if we have any valid files to process
  if @input_files.empty?
    puts "# ERROR: No valid input files found"
    raise RuntimeError, "No valid input files found"
  end
  
  @input_files.each_with_index do |file_path, file_index|
    # REQUIREMENTS: Process each file individually with proper error handling
    # SEMANTIC TOKENS: FILE_ITERATION, ERROR_HANDLING, CONTINUE_ON_ERROR
    # ARCHITECTURE: File processing loop with error recovery
    # IMPLEMENTATION: Process file with error handling and continuation
    # TEST: Test file processing with various error conditions
    
    # REQUIREMENTS: Detect file type and process accordingly
    # SEMANTIC TOKENS: FILE_TYPE_DETECTION, SOURCE_FILE_PROCESSING, ANIMATION_PROCESSING
    # ARCHITECTURE: File type detection and routing architecture
    # IMPLEMENTATION: Route files to appropriate processing methods
    # TEST: Test file type detection and routing
    file_extension = File.extname(file_path).downcase
    
    case file_extension
    when '.md', '.markdown', '.txt', '.html', '.htm'
      # Process as source file
      process_source_file(file_path, file_index)
    when '.anim'
      # Process as animation file
      process_file(file_path, file_index)
    else
      # Default to source file processing
      process_source_file(file_path, file_index)
    end
  end
  
  # REQUIREMENTS: Calculate timing gaps and finalize metadata
  # SEMANTIC TOKENS: TIMING_CALC, GAP_DETECTION, METADATA_FINALIZATION
  # ARCHITECTURE: Post-processing phase for timing and metadata
  # IMPLEMENTATION: Calculate gaps and update metadata
  # TEST: Test timing calculations and gap detection accuracy
  
  calculate_gaps
  
  
  puts "# INFO: Parsing complete. Found #{@segments.length} text segments" unless @quiet_mode
  
  # Return segments for testing and programmatic access
  @segments
end