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

Updated AudioSegmentation script to include class to interactively update missing word phonemes:
MissingWord::CommandLine?.pm script aloows a user to listen to actual audio segment that corresponds to missing word (+- 0.5 seconds before
and after location of word), and select best phoneme set (using output from g2p and HVite results on the actual audio), or modify suggested phoneme sets to better reflect actual pronunciation of a word

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Trunk/Scripts/Audio_scripts/AudioSegmentation/archive/fixMissingWords.pl

    r2612 r2613  
    55 
    66fixMissingWords  
     7 
     8=head1 Requirements 
     9 
     10Perl Package: "Term::ReadLine::Gnu" needs to be installed - required for the "preput" feature it provides 
     11Term::ReadLine is used as the front-end to Term::ReadLine::Gnu 
    712 
    813=cut  
     
    1621use Term::ANSIColor; 
    1722 
    18 my $xml = 'AudioBook/interim_files/MissingWords_combined.xml'; 
     23my $xml = 'AudioBook/interim_files/MissingWords.xml'; 
    1924my $command; 
    2025 
     
    2530my (@promptSelector, @phoneSelector); 
    2631print "VoxForge Missing Word processing (q to quit)\n"; 
     32print "(enter \"^\" to go back one entry)\n"; 
    2733print "--------------------------------------------\n"; 
    2834 
    2935my @processedWordsPhones; 
    3036my $wordNumber = 0; 
    31 my @wordList = $doc->findnodes('/ken/word'); 
     37my @wordList = $doc->findnodes('/missingwords/word'); 
    3238while (1) { 
    3339        my $wordRef = $wordList[$wordNumber]; 
     
    4349                        $wordNumber++; 
    4450                } else { 
    45                         exit; 
     51                        last; 
    4652                } 
    4753        } 
     
    5157print "completed!\n"; 
    5258 
    53 ##################################################### 
    54 # methods 
    55 ##################################################### 
     59=head1 Methods    
     60 
     61=head3 process     
     62 
     63=cut 
     64 
    5665sub process{ 
    5766        my ($wordRef,$wordNumber,$processedWordsPhones)= @_; 
    58         my $phonesPreviouslySelected = 0;        
    5967        my ($attrRef) = $wordRef->attributes(); 
    6068        my $word = $attrRef->to_literal(); 
     69        my $preput = ""; 
    6170         
    6271        displayChildNodes($wordRef); 
    63         while (defined(my $line=$term->readline($prompt))) { # get command from user   
     72        while (defined(my $line=$term->readline($prompt,$preput))) { # get command from user   
    6473                if ($line eq 'q') { 
    6574                        exit; 
     
    6978                                playAudio($promptSelector[$line]); 
    7079                        } else { 
    71                                 print color("red"), "\nselected number \"$line\" is out of range available\n" , color("reset");                                
     80                                print color("red"), "\nselected number \"$line\" is out of range\n" , color("reset");                          
    7281                        }        
    7382                } elsif ($line =~ /^[A-Za-z]$/) { # one letter  
     
    7584                        my $asciiOfFirstCharacter = ord($line); 
    7685                        if (($asciiOfFirstCharacter >= 97 ) and ($asciiOfFirstCharacter < @phoneSelector)) { 
    77                                 print "\nSelected phone set:"; 
    78                                 print color("green"),"$line:\t$phoneSelector[$asciiOfFirstCharacter]\n" , color("reset");        
    79                                 print "(press \"@\" then hit <enter> key to accept, and move to next word)\n"; 
    80                                 print "(enter \"@\" followed by your own phone sequence, and then hit <enter> key)\n"; 
    81                                 print "(enter \"^\" to go back one entry)\n"; 
    82                                 $phonesPreviouslySelected = $phoneSelector[$asciiOfFirstCharacter]; 
     86                                $preput = $phoneSelector[$asciiOfFirstCharacter];        
    8387                        } else { 
    84                                 print color("red"), "\nselected letter \"$line\" is out of range available\n" , color("reset");                                
     88                                print color("red"), "\nselected letter \"$line\" is out of range\n" , color("reset");                          
    8589                        }        
    86                 } elsif (($line eq '@') and ($phonesPreviouslySelected)) { # phoneme set selected by user 
    87                         $$processedWordsPhones[$wordNumber] = [$word,$phonesPreviouslySelected]; 
     90                } elsif ($preput) { # phoneme set selected by user 
     91                        $$processedWordsPhones[$wordNumber] = [$word,$line]; 
     92                        print color("green"), "new pron dict entry:$word\t$line\n\n" , color("reset");   
    8893                        return "next"; 
    89                 } elsif (($line =~ /^\@(.+)$/) and ($phonesPreviouslySelected)) { # phoneme set selected by user 
    90                         $$processedWordsPhones[$wordNumber] = [$word,$1]; 
    91                         return "next"; 
    92                 } elsif ($line eq '^') { # back one 
     94                }  elsif ($line eq '^') { # back one 
    9395                        if (($wordNumber -1)>0) { 
    9496                                $wordNumber = $wordNumber -1; 
     
    101103        } 
    102104} 
     105 
     106=head3 displayChildNodes  
     107 
     108=cut 
    103109 
    104110sub displayChildNodes { 
     
    143149} 
    144150 
    145 sub updateDictionary { 
    146         my ($word,$phonesSelected)= @_; 
    147         open(MISSINGWORDSFINAL,">AudioBook/interim_files/MissingWords_final") or confess ("cannot open AudioBook/interim_files/MissingWords_final file"); 
    148         foreach my $line (@$phonesSelected) { 
    149                 print "$line\n"; 
    150                 my $word = @$line[0]; 
    151                 my $phonesSelected = @$line[1]; 
    152                 print MISSINGWORDSFINAL "$word\t[$word]\t$phonesSelected\n"; 
    153         } 
    154         close MISSINGWORDSFINAL;         
    155 
     151=head3 playAudio     
     152 
     153uses ALSA aplay command line sound player to play audio 
     154         
     155=cut 
    156156 
    157157sub playAudio { 
     
    166166} 
    167167 
    168  
     168=head3 updateDictionary   
     169 
     170update pronunication dictionary 
     171 
     172=cut 
     173 
     174sub updateDictionary { 
     175        my ($processedWordsPhones)= @_; 
     176        print "updateDictionary\n"; 
     177        open(MISSINGWORDSFINAL,">AudioBook/interim_files/MissingWords_final") or confess ("cannot open AudioBook/interim_files/MissingWords_final file"); 
     178        foreach my $line (@$processedWordsPhones) { 
     179                my $word = $$line[0]; 
     180                my $phonesSelected = $$line[1]; 
     181                print MISSINGWORDSFINAL "$word\t[$word]\t$phonesSelected\n"; 
     182        } 
     183        close MISSINGWORDSFINAL;         
     184
    169185 
    170186=head1 Change Log     
     
    176192=head1 AUTHOR 
    177193     
    178     Ken MacLean 
    179     contact@voxforge.org 
     194Ken MacLean 
     195contact@voxforge.org 
    180196       
    181197=head1 COPYRIGHT AND LICENSE