- Timestamp:
- 06/17/08 15:25:27 (6 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
Trunk/Scripts/Audio_scripts/AudioSegmentation/archive/fixMissingWords.pl
r2612 r2613 5 5 6 6 fixMissingWords 7 8 =head1 Requirements 9 10 Perl Package: "Term::ReadLine::Gnu" needs to be installed - required for the "preput" feature it provides 11 Term::ReadLine is used as the front-end to Term::ReadLine::Gnu 7 12 8 13 =cut … … 16 21 use Term::ANSIColor; 17 22 18 my $xml = 'AudioBook/interim_files/MissingWords _combined.xml';23 my $xml = 'AudioBook/interim_files/MissingWords.xml'; 19 24 my $command; 20 25 … … 25 30 my (@promptSelector, @phoneSelector); 26 31 print "VoxForge Missing Word processing (q to quit)\n"; 32 print "(enter \"^\" to go back one entry)\n"; 27 33 print "--------------------------------------------\n"; 28 34 29 35 my @processedWordsPhones; 30 36 my $wordNumber = 0; 31 my @wordList = $doc->findnodes('/ ken/word');37 my @wordList = $doc->findnodes('/missingwords/word'); 32 38 while (1) { 33 39 my $wordRef = $wordList[$wordNumber]; … … 43 49 $wordNumber++; 44 50 } else { 45 exit;51 last; 46 52 } 47 53 } … … 51 57 print "completed!\n"; 52 58 53 ##################################################### 54 # methods 55 ##################################################### 59 =head1 Methods 60 61 =head3 process 62 63 =cut 64 56 65 sub process{ 57 66 my ($wordRef,$wordNumber,$processedWordsPhones)= @_; 58 my $phonesPreviouslySelected = 0;59 67 my ($attrRef) = $wordRef->attributes(); 60 68 my $word = $attrRef->to_literal(); 69 my $preput = ""; 61 70 62 71 displayChildNodes($wordRef); 63 while (defined(my $line=$term->readline($prompt ))) { # get command from user72 while (defined(my $line=$term->readline($prompt,$preput))) { # get command from user 64 73 if ($line eq 'q') { 65 74 exit; … … 69 78 playAudio($promptSelector[$line]); 70 79 } 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"); 72 81 } 73 82 } elsif ($line =~ /^[A-Za-z]$/) { # one letter … … 75 84 my $asciiOfFirstCharacter = ord($line); 76 85 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]; 83 87 } 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"); 85 89 } 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"); 88 93 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 93 95 if (($wordNumber -1)>0) { 94 96 $wordNumber = $wordNumber -1; … … 101 103 } 102 104 } 105 106 =head3 displayChildNodes 107 108 =cut 103 109 104 110 sub displayChildNodes { … … 143 149 } 144 150 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 153 uses ALSA aplay command line sound player to play audio 154 155 =cut 156 156 157 157 sub playAudio { … … 166 166 } 167 167 168 168 =head3 updateDictionary 169 170 update pronunication dictionary 171 172 =cut 173 174 sub 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 } 169 185 170 186 =head1 Change Log … … 176 192 =head1 AUTHOR 177 193 178 Ken MacLean179 contact@voxforge.org194 Ken MacLean 195 contact@voxforge.org 180 196 181 197 =head1 COPYRIGHT AND LICENSE