voxforge.org
VoxForge Dev
Show
Ignore:
Timestamp:
06/10/08 13:28:34 (7 months ago)
Author:
kmaclean
Message:

AudioSegmentation scripts - snapshot

Files:

Legend:

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

    r2608 r2609  
    112112} 
    113113 
     114=head2 getAudio  
     115 
     116get audio object. 
     117 
     118=cut 
     119 
     120sub getAudio { 
     121        my ($self)= @_;  
     122        my $audioBook = $self->{'audioBookObject'}; 
     123        my $debug = $audioBook->getDebug; 
     124 
     125        $self->verifyMissingWordPronunciations(); 
     126 
     127} 
    114128 
    115129=head2 verifyMissingWordPronunciations  
     
    133147        $dictionary->getNBestPronunciations("AudioBook/interim_files/MissingWords_alt",15); # uses Sequitor g2p to get top N pronunication vairations 
    134148        $dictionary->createAltDict($originalDict,$altDict);     # merge & sort missing_words_alt and originalDict into altDict 
    135         # !!!!!!  
    136         #$dictionary->validateAlternatePronunciations($originalDict,$altDict,$prompts); 
    137149        $self->validateAlternatePronunciations($originalDict,$altDict,$prompts); 
    138         # !!!!!! 
    139150} 
    140151 
     
    154165        my $audioBook = $self->{'audioBookObject'}; 
    155166        my $debug = $audioBook->getDebug; 
    156         # !!!!!! 
     167 
    157168        my $dictionary = $self->{'dictionaryObject'};    
    158169        my $missing_words = $dictionary->getMissing_words();     
    159         # !!!!!!! 
    160          
     170 
    161171        my $missingWordList = $self->_getMissingWordList($missing_words); 
    162172        my %prompts; 
     
    173183                        if ($missingWordList->{$word}) { # there is a missing word in this prompt line 
    174184                                my $wavfilename = $promptID . "\.wav"; 
    175                                 copy("AudioBook/interim_files/wav/$wavfilename","AudioBook/interim_files/missingWordsFolder/$wavfilename");                             
     185                                copy("AudioBook/interim_files/wav/$wavfilename","AudioBook/interim_files/missingWordsFolder/$wavfilename"); 
    176186                                push (@missingWordsPrompts,"$word:$promptID @line\n"); 
    177187                                print "\."; 
    178                                 my @phoneList = $self->_forceAlignPromptLine($altDict, $word,$promptID,\@line); # force align entire prompt line 
    179                                 push (@missingWordsValidated,"$word [$word] @phoneList\n"); 
     188                                # !!!!!! 
     189                                my ($phoneList,$startTime,$stopTime) = $self->_forceAlignPromptLine($altDict, $word,$promptID,\@line); # force align entire prompt line 
     190                                #my @phoneList = $self->_forceAlignPromptLine($altDict, $word,$promptID,\@line); # force align entire prompt line 
     191                                push (@missingWordsValidated,"$word [$word] @$phoneList\n"); 
     192                                $self->_processMissingWordAudio($promptID,$word,$startTime,$stopTime); 
     193                                # !!!!!!         
    180194                        } 
    181195                } 
     
    190204                my @temp = split (/:/,$line); 
    191205                my ($word) = shift(@temp);  
    192                 print "word:$word\n"; 
     206                #print "word:$word\n"; 
    193207                if (defined($missingWordsPrompts{$word})) { 
    194208                        my $temp = "$missingWordsPrompts{$word}\n"; 
     
    256270} 
    257271 
     272=head2 _processMissingWordAudio  
     273 
     274copy  
     275 
     276=cut 
     277 
     278sub _processMissingWordAudio { # private  
     279        my ($self,$promptID,$word,$startTime,$stopTime)= @_; 
     280        my $audioBook = $self->{'audioBookObject'}; 
     281        my $debug = $audioBook->getDebug;        
     282        my $chapter = $self->{'chapterObject'}; 
     283        my $audio = $chapter->getchapterAudioObject();  
     284                 
     285        #copy("AudioBook/interim_files/wav/$wavfilename","AudioBook/interim_files/missingWordsFolder/$wavfilename"); 
     286        my $fromFileName = "AudioBook/interim_files/wav/$promptID\.wav"; 
     287        my $toFileName = "AudioBook/interim_files/missingWordsFolder/$promptID" . "-mw\.wav"; 
     288        my $buffer = 2500000; 
     289        if ($startTime - $buffer > 0) { 
     290                $startTime = $startTime - $buffer; 
     291        } else { 
     292                $startTime = 0; 
     293        } 
     294        $stopTime = $stopTime + $buffer;        # htk will just padd the end of the file with silence if longer than full duration of file 
     295                 
     296        $audio->processMissingWordAudio($fromFileName, $startTime,$stopTime,$toFileName); 
     297         
     298        return 1; 
     299} 
     300 
    258301=head2 _forceAlignPromptLine  
    259302 
     
    261304Sequitor G2P), in doing so, it picks the most likely pronunciation, thereby validating a Sequitor G2P with real audio. 
    262305 
    263 Assumes only one missing word per prompt line 
     306Assumes only one missing word per prompt line (picks up only the first one...) 
    264307 
    265308=cut 
     
    273316        open(ALIGNED_OUT,"$aligned_out") or confess ("cannot open $aligned_out file"); 
    274317        my (@phoneList,$gatherPhones); 
     318        my ($word_startTime,$word_stopTime); 
    275319        while (my $line = <ALIGNED_OUT>) { 
    276320                my @line = split(/\s/, $line); 
     
    279323                        if ($recword eq $word) { 
    280324                                $gatherPhones=1; 
     325                                $word_startTime = $startTime; 
    281326                        } elsif ($gatherPhones) { 
     327                                $word_stopTime = $startTime; # can't search on "sp" because some words have not ending "sp" phone 
    282328                                last; 
    283329                        } 
     
    286332                        if ($phone ne "sp"){ 
    287333                                push (@phoneList,$phone); 
    288                         } 
     334                        }  
    289335                } 
    290336        }  
    291         return @phoneList
     337        return (\@phoneList,$word_startTime,$word_stopTime)
    292338} 
    293339 
     
    313359} 
    314360 
    315 =head2 getAudio  
    316  
    317 get audio object. 
    318  
    319 =cut 
    320  
    321 sub getAudio { 
    322         my ($self,$segments)= @_;        
    323         my $audioBook = $self->{'audioBookObject'}; 
    324         my $debug = $audioBook->getDebug; 
    325         # structure $fileID,"$current_word $current_startTime $current_endTime $pause" 
    326         my $promptsWithTimes = $segments->getPromptsWithTimes(); 
    327         open(MISSINGWORDS, "<AudioBook/interim_files/MissingWords") or confess ("cannot open AudioBook/output_files/prompts for output"); 
    328         my %missingwords; 
    329         foreach my $word (<MISSINGWORDS>) { 
    330                 $missingwords{$word}=1; 
    331         } 
    332         foreach my $line (@$promptsWithTimes) { 
    333                 my $fileID = $$line[0]; 
    334                 my $promptWordsWithTime = $$line[1]; 
    335                 foreach my $line (@$promptWordsWithTime) { 
    336                          
    337                 } 
    338         } 
    339          
    340         $self->{'segmentsObject'} = $segments;           
    341 } 
    342361 
    343362=head1 Change Log