voxforge.org
VoxForge Dev
Show
Ignore:
Timestamp:
06/09/08 17:06:50 (6 months ago)
Author:
kmaclean
Message:

refacture to create Chapter, Segments & MissingWords? classes - snapshop

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Trunk/Scripts/Audio_scripts/AudioSegmentation/AudioBook/Audio.pm

    r2604 r2606  
    11#! /usr/bin/perl 
    2 $VERSION = 0.2
     2$VERSION = 0.2.1
    33 
    44=head1 NAME 
    55 
    6 AudioBook::Audio - Audio processing   
     6Audio - Audio processing   
    77 
    88=cut  
     
    1414use File::Basename; 
    1515use Audio::Wav; 
    16 use lib '../'; 
     16 
    1717use AudioBook::Text; 
     18 
    1819#################################################################### 
    1920### Class Variables 
    2021#################################################################### 
    21 my (@max_sentences, $max_sentence_length_found, $max_sentence_length_linenumber); 
     22my (@max_sentences, $max_sentence_length_linenumber); 
    2223my $min_sentence_length_found = 0; 
    2324my $min_sentence_length_linenumber = 0; 
     25my $max_sentence_length_found=0; 
    2426my $up_increment = 1; 
    2527my $down_increment = -1; 
     
    3638sub new { 
    3739        my ($class,$super) = @_;  
    38         my %self; 
    39         $self{"process_audio"} = 1; 
    40         $self{'htk_files'} = $super->{'htk_files'}; 
    41         $self{'g2p_model'} = $super->{'g2p_model'}; 
    42         $self{"average_sentence_length"} = $super->{"average_sentence_length"}; 
    43         $self{"max_sentence_length"} = $super->{"max_sentence_length"}; 
    44         $min_sentence_length_found = $super->{"max_sentence_length"}; 
    45         $self{"min_pause_for_sentence_break"} = $super->{"min_pause_for_sentence_break"}; 
    46         $self{"beam_width"}= $super->{"beam_width"}; 
    47         $self{'log'} = $super->{'log'};  
    48         bless(\%self,$class); 
    49         return \%self; 
     40        my $self = {}; 
     41        bless($self,$class);     
     42        $self->{'chapterObject'} = $super; 
     43        $self->{'ChapterTextObject'} = $super->getChapterTextObject(); 
     44        my $audioBook = $super->getAudioBookObject(); 
     45        $self->{'audioBookObject'} = $audioBook; 
     46        $min_sentence_length_found = $audioBook->getMax_sentence_length(); 
     47         
     48        $self->{"process_audio"} = 1; #!!!!!! this should be set in parms?       
     49        return $self; 
    5050}     
    5151 
     
    8282} 
    8383 
    84 =head2 _createMLFFile  
     84=head2 createMLFFile  
    8585 
    8686creates an MLF (HTK required "Multi-Label File") file for a prompt. 
     
    101101=head1 INSTANCE METHODS 
    102102 
    103 =head2 segment  
     103=head1 processChapterAudio  
     104 
     105gets audio file sample rate, performs forced alignment (using HVite), and converts HVite 
     106output to includes pauses. 
     107 
     108Creates file containing "$current_word $current_startTime $current_endTime $pause" 
     109 
     110=cut 
     111 
     112sub processChapterAudio{ # public 
     113        my ($self) = @_;         
     114        my $audioBook = $self->{'audioBookObject'};              
     115        my $debug = $audioBook->getDebug;        
     116        my $log = $audioBook->getLog(); 
     117         
     118        $self->{"samplerate"} = $self->_getSampleRate(); 
     119        $self->_forceAlign();  
     120        $self->{"aligned_words"} = $self->_processHViteOutput(); 
     121        return 1; 
     122
     123 
     124=head3 _getSampleRate  
     125 
     126gets the sample rate of the audio file using Audio::Wav module 
     127 
     128=cut 
     129 
     130sub _getSampleRate { # private 
     131        my ($self) = @_;         
     132        my $audioBook = $self->{'audioBookObject'};              
     133        my $debug = $audioBook->getDebug; 
     134        #my $wavfilename = $self->{"filename"}; 
     135        my $wavfilename = $audioBook->getAudiofile(); 
     136         
     137        my $wav = new Audio::Wav  || confess "AUDIO.pm error: $?"; 
     138        my $read = $wav -> read( "$wavfilename" ) || confess "AUDIO.pm error: $?"; 
     139    my $details = $read -> details() || confess "AudioBook.pl error: $?"; 
     140        return ($$details{sample_rate}); #sampling rate 
     141
     142 
     143=head3 _forceAlign  
     144 
     145Performs "Forced Alignement" of the user submitted speech audio file.  This is the process of taking the text transcription  
     146of the speech audio file and figuring you the time stamps for each of the words.  This helps determine where the pauses are. 
     147 
     148Sox audio editor is used to downsample the audio to 16kHz-16bit - Hvite only works with 16kHz sampling rate audio 
     149 
     150The time stamps are put in the "AudioBooks/interim_files/aligned.out" file  
     151 
     152=cut 
     153 
     154sub     _forceAlign { # private 
     155        my ($self) = @_; 
     156        my $audioBook = $self->{'audioBookObject'};              
     157        my $debug = $audioBook->getDebug; 
     158        #my $filename = $self->{"filename"}; 
     159        my $filename = $audioBook->getAudiofile(); 
     160 
     161        my $htk_files = $audioBook->getHtk_files(); 
     162        my $text = $self->{"ChapterTextObject"};  
     163        my $beam_width = $audioBook->getBeam_width(); 
     164         
     165        # Hvite only works with 16kHz sampling rate audio 
     166        $command = ("sox $filename -c 1 -r 16000 -w AudioBook/interim_files/downsampled.wav"); print "$command\n" if $debug; system($command) == 0 or confess "fullrun $command failed: $?"; 
     167        # create mlf file  
     168        $text->createMLFFile("downsampled","AudioBook/interim_files/words.mlf" ); 
     169        # forced alignment - creates aligned.out 
     170        print "\nRunning HVite ...\n"; 
     171        print "check interim_files/logs/HVite_log for a possible errors\n";  
     172        print "(like \"no tokens surviving\"... which means that text *might* not exactly match audio)\n\n"; 
     173        ####################################################################     
     174        # process audio file with HVite without using a script file (i.e. -S $htk_files/train.scp); need to remove -l '*' 
     175        #HVite -A -D -T 1  -a -b SENT-END -m -C AudioBook/input_files/htk/wav_config  
     176        #   -H AudioBook/input_files/htk/models/macros  
     177        #   -H AudioBook/input_files/htk/models/hmmdefs  
     178        #   -m -t 250.0 150.0 1000.0 -I AudioBook/interim_files/words.mlf  
     179        #   -i AudioBook/interim_files/aligned.out  
     180        #   AudioBook/interim_files/dict AudioBook/input_files/htk/models/tiedlist   
     181        #   AudioBook/interim_files/downsampled.wav 
     182        # !!!!!! 
     183#       $command = ("pwd && HVite -A -D -T 1 -l '*' -a -b SENT-END -m -C $htk_files/wav_config -H $htk_files/models/macros -H $htk_files/models/hmmdefs -m -t 250.0 150.0 1000.0 -I AudioBook/interim_files/words.mlf  -i AudioBook/interim_files/aligned.out -S $htk_files/train.scp AudioBook/interim_files/dict $htk_files/models/tiedlist > AudioBook/interim_files/logs/HVite_log"); system($command) == 0 or confess "error: $command failed: $?"; 
     184        $command = ("pwd && HVite -A -D -T 1 -l '*' -a -b SENT-END -m -C $htk_files/wav_config -H $htk_files/models/macros -H $htk_files/models/hmmdefs -m -t 500.0 150.0 8000.0 -I AudioBook/interim_files/words.mlf  -i AudioBook/interim_files/aligned.out -S $htk_files/train.scp AudioBook/interim_files/dict $htk_files/models/tiedlist > AudioBook/interim_files/logs/HVite_log"); system($command) == 0 or confess "error: $command failed: $?"; 
     185# !!!!!! 
     186        open (HVite_Log,"AudioBook/interim_files/logs/HVite_log") || confess "error: can't open AudioBook/interim_files/HVite_log: $?"; 
     187        while (my $line = <HVite_Log>) { 
     188                chomp $line; 
     189                my $filename; 
     190                if ($line =~ /Aligning File:/) {  
     191                        my @line=split(/:/, $line); 
     192                        $filename = pop(@line); 
     193                } elsif ($line =~ /No tokens survived to final node of network at beam/) { 
     194                        my @line=split(/ /, $line); 
     195                        my $beam = pop (@line); 
     196                        $beam =~ s/ //g; 
     197                        print "\n\n******************************************************************\n"; 
     198                        print "**** check that audio corresponds to prompt in file ***\n"; 
     199                        print "******************************************************************\n\n"; 
     200                        if ($beam > $beam_width) { 
     201                                confess "audio not corresponding to prompt file, check HVite_Log; error code: $?" ; 
     202                        }        
     203                }  
     204        } 
     205
     206 
     207=head3 _processHViteOutput  
     208 
     209This method reads the HVite output in the "aligned.out" file (generated by the _forceAlign method) and parses it into a  
     210more user friendly format, and puts into the "AudioBooks/interim_files/htksegment_log" file.  
     211 
     212=cut 
     213 
     214sub _processHViteOutput { # private 
     215        my ($self) = @_;         
     216        my $audioBook = $self->{'audioBookObject'};              
     217        my $debug = $audioBook->getDebug; 
     218                 
     219        open(ALIGNED, "<AudioBook/interim_files/aligned.out") or confess ("can\'t open AudioBook/interim_files/aligned.out file for reading");  
     220        my @aligned = <ALIGNED>; 
     221        close ALIGNED; 
     222        my ($pause, @aligned_words, $current_word, $current_startTime, $current_endTime); 
     223        my $first_pass = 1; 
     224        foreach my $line (@aligned) { 
     225                chomp $line; 
     226                my @labels = split(/ /, $line);  
     227                #print "@labels\n"; 
     228                my ($startTime,$endTime,$phone,$score,$word)= @labels;   
     229                if (!defined($word)) {$word=""}; 
     230                if (!defined($phone)) {$phone=""}; 
     231                if ($phone eq "sp") { 
     232                        $pause = $endTime - $startTime; 
     233                } 
     234                if (($word ne "") and ($word ne "SENT-END") and ($first_pass)) {         
     235                        $current_word = $word;           
     236                        $current_startTime = $startTime; 
     237                        $first_pass = undef;                                     
     238                } elsif (($word ne "") and (!$first_pass)) {     
     239                        #print  "$startTime,$endTime,$phone,$score,$word,pause:$pause\n"; 
     240                        $current_endTime = $startTime-$pause; 
     241                        push (@aligned_words, "$current_word $current_startTime $current_endTime $pause");       
     242                        $current_word = $word;           
     243                        $current_startTime = $startTime;                         
     244                }        
     245        } 
     246        open(HTKLOG, ">AudioBook/interim_files/htksegment_log") or confess ("cannot open htksegment_log for output");    
     247        foreach my $line (@aligned_words) { 
     248                print HTKLOG "$line\n"; 
     249        } 
     250        close (HTKLOG); 
     251 
     252        return (\@aligned_words); 
     253
     254 
     255=head1 createSegmentedAudio  
    104256 
    105257Public Method that does the actual segmentation of the speech audio file using the text file supplied by the user.  
     
    110262=cut 
    111263 
    112 sub segment { # public 
    113         my ($self,$filename,$textContents) = @_;         
    114         my $debug = $self->{"debug"};            
    115         my $log = $self->{"log"}; 
    116          
     264sub createSegmentedAudio { # public 
     265        my ($self) = @_;         
     266        my $audioBook = $self->{'audioBookObject'};              
     267        my $debug = $audioBook->getDebug;        
     268        my $log = $audioBook->getLog();  
     269        my $aligned_words = $self->{"aligned_words"}; 
     270         
     271        #my $filename = $self->{'filename'}; 
     272        my $filename = $audioBook->getAudiofile(); 
    117273        my $filename_nopath = basename($filename); 
    118274        my $filename_nosuffix = fileparse($filename, "wav"); 
     
    122278        $self->{"filename_nopath"} = $filename_nopath; 
    123279        $self->{"filename_prefix"} = lc(substr($filename_nopath,0,3)); 
    124         $self->{"textContents"} = $textContents; 
    125          
    126         my $average_sentence_length = $self->{"average_sentence_length"}; 
    127         my $max_sentence_length = $self->{"max_sentence_length"}; 
    128         my $min_pause_for_sentence_break = $self->{"min_pause_for_sentence_break"}; 
    129  
    130         my $samplerate = _getSampleRate($self); 
    131         $self->{"samplerate"} = $samplerate; 
    132            
    133         _forceAlign($self);  
    134         my $aligned_words= $self->_processHViteOutput(); 
    135         $self->{"aligned_words"} = $aligned_words; 
     280         
     281        my $average_sentence_length = $audioBook->getAverage_sentence_length(); 
     282        my $max_sentence_length =  $audioBook->getMax_sentence_length(); 
     283        my $min_pause_for_sentence_break = $audioBook->getMin_pause_for_sentence_break(); 
    136284                 
    137         print "\nSegmenting:$filename (each dot represents a newly created segmented audio file)\n";     
    138         print "-------------------------------------------------------------------------------\n";               
     285        print "\nSegmenting:$filename\n"; 
     286        print "(each dot represents a newly created segmented audio file)\n";    
     287        print "----------------------------------------------------------\n";            
    139288        # copy to "interim_files"" directory for processing; also converts to 16 bits per sample (-w=16-bits) so it can be processed by HVite 
    140         $command = ("sox $filename -w AudioBook/interim_files/$filename_nopath"); print "$command\n"; system($command) == 0 or confess "fullrun $command failed: $?";  
     289        $command = ("sox $filename -w AudioBook/interim_files/$filename_nopath"); print "$command\n" if $debug; system($command) == 0 or confess "fullrun $command failed: $?";  
    141290         
    142291        my $loop; 
     
    204353} 
    205354 
    206 =head3 _getSampleRate  
    207  
    208 gets the sample rate of the audio file using Audio::Wav module 
    209  
    210 =cut 
    211  
    212 sub _getSampleRate { # private 
    213         my ($self) = @_;         
    214         my $debug = $self->{"debug"}; 
    215         my $wavfilename = $self->{"filename"}; 
    216          
    217         my $wav = new Audio::Wav  || confess "AUDIO.pm error: $?"; 
    218         my $read = $wav -> read( "$wavfilename" ) || confess "AUDIO.pm error: $?"; 
    219     my $details = $read -> details() || confess "AudioBook.pl error: $?"; 
    220         return ($$details{sample_rate}); #sampling rate 
    221 } 
    222  
    223 =head3 _forceAlign  
    224  
    225 Performs "Forced Alignement" of the user submitted speech audio file.  This is the process of taking the text transcription  
    226 of the speech audio file and figuring you the time stamps for each of the words.  This helps determine where the pauses are. 
    227  
    228 Sox audio editor is used to downsample the audio to 16kHz-16bit - Hvite only works with 16kHz sampling rate audio 
    229  
    230 The time stamps are put in the "AudioBooks/interim_files/aligned.out" file  
    231  
    232 =cut 
    233  
    234 sub     _forceAlign { # private 
    235         my ($self) = @_;         
    236         my $debug = $self->{"debug"};    
    237         my $filename = $self->{"filename"}; 
    238         my $htk_files = $self->{'htk_files'}; 
    239         my $textContents = $self->{"textContents"};  
    240         my $beam_width = $self->{"beam_width"}; 
    241          
    242         # Hvite only works with 16kHz sampling rate audio 
    243         $command = ("sox $filename -c 1 -r 16000 -w AudioBook/interim_files/downsampled.wav"); print "$command\n"; system($command) == 0 or confess "fullrun $command failed: $?"; 
    244         # create mlf file  
    245         $textContents->createMLFFile("downsampled","AudioBook/interim_files/words.mlf" ); 
    246         # forced alignment - creates aligned.out 
    247         print "\nRunning HVite ...\n"; 
    248         print "check interim_files/logs/HVite_log for a possible errors\n";  
    249         print "(like \"no tokens surviving\"... which means that text does not match audio)\n\n"; 
    250         ####################################################################     
    251         # process audio file with HVite without using a script file (i.e. -S $htk_files/train.scp); need to remove -l '*' 
    252         #HVite -A -D -T 1  -a -b SENT-END -m -C AudioBook/input_files/htk/wav_config  
    253         #   -H AudioBook/input_files/htk/models/macros  
    254         #   -H AudioBook/input_files/htk/models/hmmdefs  
    255         #   -m -t 250.0 150.0 1000.0 -I AudioBook/interim_files/words.mlf  
    256         #   -i AudioBook/interim_files/aligned.out  
    257         #   AudioBook/interim_files/dict AudioBook/input_files/htk/models/tiedlist   
    258         #   AudioBook/interim_files/downsampled.wav 
    259         # !!!!!! 
    260 #       $command = ("pwd && HVite -A -D -T 1 -l '*' -a -b SENT-END -m -C $htk_files/wav_config -H $htk_files/models/macros -H $htk_files/models/hmmdefs -m -t 250.0 150.0 1000.0 -I AudioBook/interim_files/words.mlf  -i AudioBook/interim_files/aligned.out -S $htk_files/train.scp AudioBook/interim_files/dict $htk_files/models/tiedlist > AudioBook/interim_files/logs/HVite_log"); system($command) == 0 or confess "error: $command failed: $?"; 
    261         $command = ("pwd && HVite -A -D -T 1 -l '*' -a -b SENT-END -m -C $htk_files/wav_config -H $htk_files/models/macros -H $htk_files/models/hmmdefs -m -t 500.0 150.0 8000.0 -I AudioBook/interim_files/words.mlf  -i AudioBook/interim_files/aligned.out -S $htk_files/train.scp AudioBook/interim_files/dict $htk_files/models/tiedlist > AudioBook/interim_files/logs/HVite_log"); system($command) == 0 or confess "error: $command failed: $?"; 
    262 # !!!!!! 
    263         open (HVite_Log,"AudioBook/interim_files/logs/HVite_log") || confess "error: can't open AudioBook/interim_files/HVite_log: $?"; 
    264         while (my $line = <HVite_Log>) { 
    265                 chomp $line; 
    266                 my $filename; 
    267                 if ($line =~ /Aligning File:/) {  
    268                         my @line=split(/:/, $line); 
    269                         $filename = pop(@line); 
    270                 } elsif ($line =~ /No tokens survived to final node of network at beam/) { 
    271                         my @line=split(/ /, $line); 
    272                         my $beam = pop (@line); 
    273                         $beam =~ s/ //g; 
    274                         print "\n\n******************************************************************\n"; 
    275                         print "**** check that audio corresponds to prompt in file ***\n"; 
    276                         print "******************************************************************\n\n"; 
    277                         if ($beam > $beam_width) { 
    278                                 confess "audio not corresponding to prompt file, check HVite_Log; error code: $?" ; 
    279                         }        
    280                 }  
    281         } 
    282 } 
    283  
    284 =head3 _processHViteOutput  
    285  
    286 This method reads the HVite output in the "aligned.out" file (generated by the _forceAlign method) and parses it into a  
    287 more user friendly format, and puts into the "AudioBooks/interim_files/htksegment_log" file.  
    288  
    289 =cut 
    290  
    291 sub _processHViteOutput { # private 
    292         my ($self) = @_;         
    293         my $debug = $self->{"debug"};    
    294                  
    295         open(ALIGNED, "<AudioBook/interim_files/aligned.out") or confess ("can\'t open AudioBook/interim_files/aligned.out file for reading");  
    296         my @aligned = <ALIGNED>; 
    297         close ALIGNED; 
    298         my ($pause, @aligned_words, $current_word, $current_startTime, $current_endTime); 
    299         my $first_pass = 1; 
    300         foreach my $line (@aligned) { 
    301                 chomp $line; 
    302                 my @labels = split(/ /, $line);  
    303                 #print "@labels\n"; 
    304                 my ($startTime,$endTime,$phone,$score,$word)= @labels;   
    305                 if (!defined($word)) {$word=""}; 
    306                 if (!defined($phone)) {$phone=""}; 
    307                 if ($phone eq "sp") { 
    308                         $pause = $endTime - $startTime; 
    309                 } 
    310                 if (($word ne "") and ($word ne "SENT-END") and ($first_pass)) {         
    311                         $current_word = $word;           
    312                         $current_startTime = $startTime; 
    313                         $first_pass = undef;                                     
    314                 } elsif (($word ne "") and (!$first_pass)) {     
    315                         #print  "$startTime,$endTime,$phone,$score,$word,pause:$pause\n"; 
    316                         $current_endTime = $startTime-$pause; 
    317                         push (@aligned_words, "$current_word $current_startTime $current_endTime $pause");       
    318                         $current_word = $word;           
    319                         $current_startTime = $startTime;                         
    320                 }        
    321         } 
    322         open(LOG, ">AudioBook/interim_files/htksegment_log") or confess ("cannot open htksegment_log for output");       
    323         foreach my $line (@aligned_words) { 
    324                 print LOG "$line\n"; 
    325         } 
    326         close (LOG); 
    327  
    328         return (\@aligned_words); 
    329 } 
    330  
    331355=head3 _sentence_test  
    332356 
     
    338362sub _sentence_test { # private 
    339363        my ($self, $where, $increment,$aligned_words, $fileid, $sentence_start, $sentence_end) = @_; 
    340         my $debug = $self->{"debug"};    
     364        my $audioBook = $self->{'audioBookObject'};              
     365        my $debug = $audioBook->getDebug;        
     366        my $average_sentence_length = $audioBook->getAverage_sentence_length(); 
     367        my $min_pause_for_sentence_break = $audioBook->getMin_pause_for_sentence_break(); 
    341368        my $filename_prefix = $self->{"filename_prefix"}; 
    342         my $average_sentence_length = $self->{"average_sentence_length"}; 
    343         #my $max_sentence_length = $self->{"max_sentence_length"}; 
    344         my $min_pause_for_sentence_break = $self->{"min_pause_for_sentence_break"}; 
    345369         
    346370        my @aligned_line = split(/\s/,$$aligned_words[$$sentence_end + $increment]); 
     
    415439sub _calculateStats { # Calculate min and max sentence 
    416440        my ($self,$sentence_start,$sentence_end,$increment,$filename_prefix,$padded_fileid ) = @_; 
    417         my $debug = $self->{"debug"};    
    418         #my $average_sentence_length = $self->{"average_sentence_length"}; 
    419         my $max_sentence_length = $self->{"max_sentence_length"}; 
    420         #my $min_pause_for_sentence_break = $self->{"min_pause_for_sentence_break"}; 
     441        my $audioBook = $self->{'audioBookObject'};              
     442        my $debug = $audioBook->getDebug;        
     443        my $max_sentence_length = $audioBook->getMax_sentence_length(); 
    421444         
    422445        if ($debug) { 
     
    433456                push (@max_sentences,"$filename_prefix$padded_fileid:" . ($sentence_length+1)); 
    434457        }  
     458        #print "!!!!!!!sentence_length:$sentence_length;min_sentence_length_found:$min_sentence_length_found\n"; 
     459        #print "!!!!!!!sentence_length:$sentence_length>max_sentence_length_found:$max_sentence_length_found\n"; 
    435460        if ($sentence_length<$min_sentence_length_found) { 
    436461        $min_sentence_length_found = $sentence_length+1;  
     
    450475sub _last_sentence { # private 
    451476        my ($self, $aligned_words, $fileid, $sentence_start, $sentence_end) = @_; 
    452         my $debug = $self->{"debug"};    
     477        my $audioBook = $self->{'audioBookObject'};              
     478        my $debug = $audioBook->getDebug;        
    453479        my $filename_prefix = $self->{"filename_prefix"}; 
    454480        my ($count, $startTime); 
     
    489515sub _processAudio { # private 
    490516        my ($self, $startTime, $endTime,$padded_fileid) = @_; 
    491         my $debug = $self->{"debug"};    
     517        my $audioBook = $self->{'audioBookObject'};              
     518        my $debug = $audioBook->getDebug;        
    492519        my $process_audio = $self->{"process_audio"}; 
    493520        my $samplerate = $self->{"samplerate"}; 
    494521        my $filename_prefix = $self->{"filename_prefix"}; 
    495522        my $filename_nopath = $self->{"filename_nopath"}; 
    496         my $htk_files = $self->{'htk_files'}
     523        my $htk_files = $audioBook->getHtk_files()
    497524 
    498525        #print "debug:$debug;process_audio:$process_audio:\n"; 
     
    513540=head2 verifySegments  
    514541 
    515 Create a segmented audio file from the original audio file using startTime and endTime generated from segmentation routines. 
    516  
    517542Second pass Forced Alignment on the segmented audio files generated from the segment method.  It tries to perform forced aligment  
    518 on each individual segmented audio file using the corresponded prompt line, to confirm that they match.  If they do not, it flags  
    519 the prompt for further editing.  
     543on each individual segmented audio file using the corresponded prompt line, to confirm that the text matches the what was said 
     544in the audio file.  If they do not match, it flags the promptID, so that you can manually correct any errors.  
    520545  
    521546=cut 
     
    523548sub verifySegments { #public 
    524549        my ($self) = @_;                 
    525         my $debug = $self->{"debug"};    
    526         my $log = $self->{"log"}; 
     550        my $audioBook = $self->{'audioBookObject'};              
     551        my $debug = $audioBook->getDebug;        
     552        my $log = $audioBook->getLog; 
    527553         
    528554        open(LOG,">>$log") or confess ("cannot open $log file"); 
     
    533559        print "-------------------------------------------------------------\n";                 
    534560        open(PROMPTS, "<AudioBook/interim_files/prompts") or confess ("cannot open AudioBook/output_files/prompts for output"); 
     561        my @promptsWithTimes; 
    535562        my @promptScores;        
    536563        foreach my $line (<PROMPTS>) { 
     
    544571                my $avgLogLikelihoodPerFrame = $self->_processHviteLog($wavfilename); 
    545572                push (@promptScores,[$avgLogLikelihoodPerFrame,$fileID,"@promptList"]); 
     573                # !!!!!! 
     574                push (@promptsWithTimes,[$fileID,$self->_processHViteOutput()]); # converts aligned.out to htksegment_log 
     575                # !!!!!! 
    546576                print "\."; 
    547577        } 
    548578        print "\n"; 
    549579        close (PROMPTS);                 
    550         close (MLF);           
     580        #close (MLF);          
    551581        #my @sortedlist = sort @promptScores; 
    552582        my @sortedlist = sort { $a->[0] cmp $b->[0] } (@promptScores); # sort of 1st element of @promptScores (which is an array of arrays) 
     
    563593        } 
    564594        close LOG; 
     595         
     596        $self->{"promptsWithScores"} = \@promptScores; 
     597        return (\@promptsWithTimes); 
    565598} 
    566599 
     
    573606sub _createMLFFile { # private 
    574607        my ($self,$promptList)= @_; 
    575         my $debug = $self->{"debug"};    
     608        my $audioBook = $self->{'audioBookObject'};              
     609        my $debug = $audioBook->getDebug;                
    576610        open(MLF, ">AudioBook/interim_files/segment.mlf") or confess ("cannot open AudioBook/interim_files/segment.mlf for output");     
    577611        print MLF "#!MLF!#\n"; #  
     
    591625sub _forceAlignSegment {  # private 
    592626        my ($self,$wavfilename, $segmentMLF)= @_; 
    593         my $debug = $self->{"debug"};    
    594         my $htk_files = $self->{'htk_files'}; 
     627        my $audioBook = $self->{'audioBookObject'};              
     628        my $debug = $audioBook->getDebug;        
     629        my $htk_files = $audioBook->getHtk_files(); 
    595630 
    596631        $command = ("sox AudioBook/interim_files/wav/$wavfilename -c 1 -r 16000 -w AudioBook/interim_files/downsampled.wav 2>&1 > AudioBook/interim_files/logs/Segment_Soxlog"); system($command) == 0 or confess "$command failed: $?"; 
     
    608643sub _processHviteLog {  # private 
    609644        my ($self,$wavfilename)= @_; 
    610         my $debug = $self->{"debug"};    
    611         my $beam_width = $self->{"beam_width"}; 
     645        my $audioBook = $self->{'audioBookObject'};              
     646        my $debug = $audioBook->getDebug; 
     647        my $beam_width = $audioBook->getBeam_width(); 
    612648        my $avgLogLikelihoodPerFrame; 
    613649        my $log = $self->{"log"};        
     
    672708=head1 Change Log     
    673709 
    674         2008/05/02 - 0.2 - Convert to class; major refacture; renamed from htksegment to Audio.pm 
    675         2007/06/12 - 0.1.2 - modularize code 
    676         2007.03.22 - 0.1 - created 
     7102008/06/09 - 0.2.1 - refacture to create Chapter, Segments & MissingWords classes 
     7112008/05/02 - 0.2 - Convert to class; major refacture; renamed from htksegment to Audio.pm 
     7122007/06/12 - 0.1.2 - modularize code 
     7132007.03.22 - 0.1 - created 
    677714         
    678715=head1 Current Unresolved Issues: