Class: AudioStitcher

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

Overview

Audio Stitcher REQUIREMENTS: Create AudioStitcher class for combining segments SEMANTIC TOKENS: AUDIO_STITCHER_CLASS, AUDIO_COMBINATION ARCHITECTURE: Audio stitching architecture with timing synchronization IMPLEMENTATION: Combine audio segments with silence gaps TEST: Test audio stitching and silence gap insertion

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ AudioStitcher

REQUIREMENTS: Initialize audio stitcher with configuration SEMANTIC TOKENS: AUDIO_STITCHER_INIT, STITCHER_CONFIG ARCHITECTURE: Audio stitcher initialization architecture IMPLEMENTATION: Initialize with output format and timing settings TEST: Test audio stitcher initialization and configuration



1769
1770
1771
1772
1773
1774
1775
1776
# File 'lib/parse_animation_to_tts.rb', line 1769

def initialize(config = {})
  @config = config
  @output_format = config[:output_format] || 'wav'
  @sample_rate = config[:sample_rate] || 44100
  @temp_dir = config[:temp_dir] || Dir.mktmpdir
  @quiet_mode = config[:quiet] || false
  @stitched_segments = []
end

Instance Method Details

#cleanupObject

REQUIREMENTS: Clean up stitched audio files SEMANTIC TOKENS: STITCHED_AUDIO_CLEANUP, OUTPUT_FILE_CLEANUP ARCHITECTURE: Stitched audio cleanup architecture IMPLEMENTATION: Clean up stitched audio files TEST: Test stitched audio file cleanup



1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
# File 'lib/parse_animation_to_tts.rb', line 1836

def cleanup
  # REQUIREMENTS: Remove stitched audio files
  # SEMANTIC TOKENS: STITCHED_FILE_CLEANUP, OUTPUT_CLEANUP
  # ARCHITECTURE: Stitched file cleanup architecture
  # IMPLEMENTATION: Remove stitched audio files
  # TEST: Test stitched file cleanup
  @stitched_segments.each do |stitched_segment|
    output_file = stitched_segment['output_file']
    if File.exist?(output_file)
      File.delete(output_file)
      puts "# INFO: Cleaned up stitched audio file: #{output_file}"
    end
  end
  
  @stitched_segments.clear
end

#stitch_segments(segments_metadata, gaps_metadata, output_file = nil) ⇒ Object

REQUIREMENTS: Stitch audio segments with silence gaps SEMANTIC TOKENS: AUDIO_STITCHING, SILENCE_GAP_INSERTION ARCHITECTURE: Audio stitching with timing synchronization IMPLEMENTATION: Combine segments with calculated silence gaps TEST: Test audio stitching and silence gap insertion



1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
# File 'lib/parse_animation_to_tts.rb', line 1783

def stitch_segments(, , output_file = nil)
  # REQUIREMENTS: Validate input metadata
  # SEMANTIC TOKENS: METADATA_VALID, INPUT_VALID
  # ARCHITECTURE: Input validation architecture
  # IMPLEMENTATION: Validate segments and gaps metadata
  # TEST: Test input validation and error handling
  (, )
  
  # REQUIREMENTS: Create output file path
  # SEMANTIC TOKENS: OUTPUT_FILE_CREATE, FILE_PATH_GEN
  # ARCHITECTURE: Output file path generation
  # IMPLEMENTATION: Generate unique output file path or use provided path
  # TEST: Test output file path generation
  output_file ||= create_output_file_path
  
  # REQUIREMENTS: Stitch segments with silence gaps
  # SEMANTIC TOKENS: SEGMENT_STITCHING, SILENCE_INSERTION
  # ARCHITECTURE: Segment stitching architecture
  # IMPLEMENTATION: Combine segments with calculated silence gaps
  # TEST: Test segment stitching with silence gaps
  stitch_audio_files(, , output_file)
  
  # REQUIREMENTS: Create stitching metadata
  # SEMANTIC TOKENS: STITCHING_METADATA_CREATE, OUTPUT_METADATA
  # ARCHITECTURE: Stitching metadata architecture
  # IMPLEMENTATION: Create metadata for stitched audio file
  # TEST: Test stitching metadata creation
   = (, , output_file)
  
  # REQUIREMENTS: Track stitched segments
  # SEMANTIC TOKENS: STITCHED_SEGMENT_TRACKING, OUTPUT_TRACKING
  # ARCHITECTURE: Stitched segment tracking architecture
  # IMPLEMENTATION: Track stitched segments for cleanup
  # TEST: Test stitched segment tracking
  @stitched_segments << 
  
  
end

#stitched_segmentsObject

REQUIREMENTS: Get stitched segments metadata SEMANTIC TOKENS: STITCHED_SEGMENTS_ACCESS, OUTPUT_METADATA_ACCESS ARCHITECTURE: Stitched segments access architecture IMPLEMENTATION: Provide access to stitched segments metadata TEST: Test stitched segments metadata access



1827
1828
1829
# File 'lib/parse_animation_to_tts.rb', line 1827

def stitched_segments
  @stitched_segments.dup
end