voxforge.org
VoxForge Dev
Show
Ignore:
Timestamp:
05/30/08 14:49:08 (6 months ago)
Author:
kmaclean
Message:

AudioSegmentation scripts - snapshot

Files:

Legend:

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

    r2598 r2599  
    1212use diagnostics; 
    1313use Carp; 
     14use File::Copy; 
    1415use Lingua::EN::Numbers qw(num2en num2en_ordinal); 
    1516use Lingua::EN::Numbers::Years; 
     
    176177 
    177178Add alternate pronunications generated by Sequitor G2P to original dict file, then perform forced alingment to see which 
    178 pronunciation that HVite picks, based on the phonemes it recognizes from the audio. 
     179pronunciation that HVite picks, based on the phonemes it recognizes in the audio. 
    179180 
    180181Also create a folder containing the missing words and a prompt file containing with only those prompts that contain the missing words, 
    181 for manual confirmation of pronunciations. 
     182for manual confirmation of pronunciations.   
     183todo: set this up as an audacity project containing the wav files and text prompts. 
    182184 
    183185=cut 
     
    188190        my $missing_words = $self->{'missing_words'};    
    189191         
    190         $self->_createAltDict($originalDict,$altDict); 
    191192        my $missingWordList = $self->_getMissingWordList($missing_words); 
    192193        my %prompts; 
    193194        open(PROMPTS,"$prompts") or confess ("cannot open $prompts file"); 
    194         open(MISSINGWORDPROMPTS,"AudioBook/interim_files/missingWordsFolder/missingWordPrompts") or confess ("cannot open AudioBook/interim_files/wav/missingWordPrompts file");               
    195         open(MISSINGWORDSVAL,"AudioBook/interim_files/missingWords_val") or confess ("cannot open AudioBook/interim_files/wav/missingWordPrompts file");               
     195        open(MISSINGWORDPROMPTS,">AudioBook/interim_files/missingWordsFolder/missingWordPrompts") or confess ("cannot open AudioBook/interim_files/wav/missingWordPrompts file");              
     196        open(MISSINGWORDSVAL,">AudioBook/interim_files/missingWords_validated") or confess ("cannot open AudioBook/interim_files/missingWords_validated file");                
    196197        while (my $line = <PROMPTS>) {  
    197198                chomp $line;     
     
    199200                my $promptID = shift @line; 
    200201                foreach my $word (@line) { 
    201                         if ($missingWordList->{$word}) { 
     202                        if ($missingWordList->{$word}) { # there is a missing word in this prompt line 
    202203                                my $wavfilename = $promptID . "\.wav"; 
    203204                                copy("AudioBook/interim_files/wav/$wavfilename","AudioBook/interim_files/missingWordsFolder/$wavfilename");                              
    204205                                print MISSINGWORDPROMPTS "$word:$promptID,@line\n"; 
    205                                 my @phoneList = _forceAlignPromptLine($word,$promptID,@line); 
     206                                my @phoneList = $self->_forceAlignPromptLine($altDict, $word,$promptID,\@line); # force align entire prompt line 
    206207                                print MISSINGWORDSVAL "$word [$word] @phoneList\n"; 
    207208                        } 
     
    217218Sequitor G2P), in doing so, it picks the most likely pronunciation, thereby validating a Sequitor G2P with real audio. 
    218219 
     220Assumes only one missing word per prompt line 
     221 
    219222=cut 
    220223 
    221224sub _forceAlignPromptLine { # private  
    222         my ($self,$word,$promptID,$promptLine)= @_; 
    223         my $altDict = $self->{"altDict"};       
    224         my ($aligned_out, $log) = AudioBook::Audio::forceAlign($self, $promptID, $promptLine, $altDict); 
     225        my ($self,$altDict,$word,$promptID,$promptLine)= @_; 
     226         
     227        my ($aligned_out, $log) = AudioBook::Audio->forceAlign($self, $promptID, $promptLine, $altDict); 
    225228        open(ALIGNED_OUT,"$aligned_out") or confess ("cannot open $aligned_out file"); 
    226229        my (@phoneList,$gatherPhones); 
     230        print "_forceAlignPromptLine:word=$word\n"; 
    227231        while (my $line = <ALIGNED_OUT>) { 
    228232                my @line = split(/\s/, $line); 
     233                print "_forceAlignPromptLine:line:@line\n"; 
    229234                my($startTime,$stopTime, $phone, $probability, $recword) = @line; 
     235                print "_forceAlignPromptLine:$startTime,$stopTime, $phone, $probability, $recword\n"; 
    230236                if (defined($recword)) { 
    231237                        if ($recword eq $word) { 
    232238                                $gatherPhones=1; 
    233                         } else
    234                                 $gatherPhones=0
     239                        } elsif ($gatherPhones)
     240                                last
    235241                        } 
    236                 } 
     242                }  
     243 
    237244                if ($gatherPhones) { 
    238                         push (@phoneList,$phone); 
     245                        if ($phone ne "sp"){ 
     246                                push (@phoneList,$phone); 
     247                        } 
    239248                } 
    240249        }  
     
    262271=head2 createAltDict  
    263272 
    264 Need to merge the output from Sequitor G2P in getAlternatePronunciations() to the dict for the submission 
    265  
    266 (todo: may need to create individual dict files for each out-of-vocabulary word to speed things up) 
    267  
    268 =cut 
    269  
    270 sub _createAltDict { # private  
     273Merge the output from Sequitor G2P to HDMan's dict file (for the submission... this is not dict file for a particular prompt line) 
     274 
     275todo: may need to create individual dict files for each out-of-vocabulary word to speed things up 
     276 
     277=cut 
     278 
     279sub createAltDict { #  
    271280        my ($self,$originalDict,$altDict)= @_; 
    272281        my $missing_words_alt = $self->{"missing_words_alt"};    
    273282         
    274         $self->{"altDict"} = $altDict;   
    275  
    276283        open(MISSINGWORDSALT,"$missing_words_alt") or confess ("cannot open $missing_words_alt file"); 
    277284        my @missingWordAlt;