Changeset 2615 for Trunk/Scripts/Audio_scripts/AudioSegmentation/AudioBook/MissingWords/CommandLine.pm
- Timestamp:
- 06/18/08 21:42:49 (6 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
Trunk/Scripts/Audio_scripts/AudioSegmentation/AudioBook/MissingWords/CommandLine.pm
r2614 r2615 47 47 $self->{'term'} = Term::ReadLine->new("Missing_Word_Processing"); 48 48 49 $self->{'promptSelectorA'} = []; 50 $self->{'phoneSelectorA'} = []; 49 # !!!!!! 50 #$self->{'promptSelectorA'} = []; 51 #$self->{'phoneSelectorA'} = []; 52 # !!!!!! 51 53 return $self; 52 54 } … … 64 66 my $doc = $self->{'doc'}; 65 67 66 print "VoxForge Missing Word processing ( qto quit)\n";68 print "VoxForge Missing Word processing (\$ to quit)\n"; 67 69 print "(enter \"^\" to go back one entry)\n"; 68 70 print "--------------------------------------------\n"; … … 89 91 } 90 92 } 91 92 93 updateDictionary(\@processedWordsPhones); 93 94 } … … 101 102 sub process{ 102 103 my ($self,$wordRef,$wordNumber,$processedWordsPhones,$totalNumberOfWords)= @_; 104 # !!!!!! 105 $self->{'promptSelectorA'} = []; 106 $self->{'phoneSelectorA'} = []; 107 # !!!!!! 103 108 my $promptSelectorA = $self->{'promptSelectorA'}; 104 109 my $phoneSelectorA = $self->{'phoneSelectorA'}; 105 110 106 111 my $doc = $self->{'doc'}; 107 112 my $term= $self->{'term'}; … … 113 118 $self->displayChildNodes($wordRef,$wordNumber,$totalNumberOfWords); 114 119 while (defined(my $line=$term->readline($prompt,$preput))) { # get command from user 115 if ($line eq ' q') {120 if ($line eq '$') { 116 121 exit; 117 } elsif ($line =~ /^\d+$/) { # digit118 $self->displayChildNodes($wordRef,$wordNumber,$totalNumberOfWords);122 } elsif ($line =~ /^\d+$/) { # one or more numbers 123 #$self->displayChildNodes($wordRef,$wordNumber,$totalNumberOfWords); 119 124 if (($line > 0) and ($line < @$promptSelectorA)) { 120 $self->playAudio($$promptSelectorA[$line]); 121 } else { 122 print color("red"), "\nselected number \"$line\" is out of range\n" , color("reset"); 125 # !!!!!! 126 #my $fullpath = "AudioBook/interim_files/missingWordsFolder/" . $audioFile . "-mw.wav"; 127 #$self->playAudio($$promptSelectorA[$line]); 128 my $fullpath = "AudioBook/interim_files/missingWordsFolder/" . $$promptSelectorA[$line] . "-mw.wav"; 129 $self->playAudio($$promptSelectorA[$line], $fullpath); 130 $preput = ""; 131 # !!!!!! 132 } else { 133 print color("red"), "selected number \"$line\" is out of range" , color("reset"); 134 print "\n"; 135 } 136 } elsif ($line =~ /^(\d+)\*$/) { # one or more numbers + star 137 my $digit = $1; 138 if (($digit > 0) and ($digit < @$promptSelectorA)) { 139 my $fullpath = "AudioBook/interim_files/missingWordsFolder/" . $$promptSelectorA[$digit] . ".wav"; 140 $self->playAudio($$promptSelectorA[$digit], $fullpath); 141 } else { 142 print color("red"), "selected number \"$digit\" is out of range" , color("reset"); 143 print "\n"; 123 144 } 124 145 } elsif ($line =~ /^[A-Za-z]$/) { # one letter 125 $self->displayChildNodes($wordRef,$wordNumber,$totalNumberOfWords);146 #$self->displayChildNodes($wordRef,$wordNumber,$totalNumberOfWords); 126 147 my $asciiOfFirstCharacter = ord($line); 127 148 if (($asciiOfFirstCharacter >= 97 ) and ($asciiOfFirstCharacter < @$phoneSelectorA)) { 128 149 $preput = $$phoneSelectorA[$asciiOfFirstCharacter]; 129 150 } else { 130 print color("red"), "\nselected letter \"$line\" is out of range\n" , color("reset"); 151 print color("red"), "selected letter \"$line\" is out of range" , color("reset"); 152 print "\n"; 131 153 } 132 154 } elsif ($preput) { # phoneme set selected by user 133 155 $$processedWordsPhones[$wordNumber] = [$word,$line]; 134 print color("green"), "new pron dict entry:$word\t$line\n\n" , color("reset"); 156 print color("blue"), "new pron dict entry:$word\t$line\n" , color("reset"); 157 print "--------------------\n\n"; 135 158 return "next"; 136 159 } elsif ($line eq '^') { # back one … … 141 164 } else { 142 165 $self->displayChildNodes($wordRef,$wordNumber,$totalNumberOfWords); 143 print color("red"), " \nonly numbers or single characters permitted\n" , color("reset");166 print color("red"), "only numbers or single characters permitted\n" , color("reset"); 144 167 } 145 168 } … … 163 186 my @childNodes = $wordRef->childNodes; 164 187 165 print $wordRef->nodeName . " " . ($wordNumber +1) ." of " . $totalNumberOfWords . ":";166 print color(" green"), $word . "\n" , color("reset");188 print color("green"),$wordRef->nodeName . " " . ($wordNumber +1) ." of " . $totalNumberOfWords . ":"; 189 print color("blue"), $word . "\n" , color("reset"); 167 190 foreach my $child (@childNodes) { 168 191 if ($child->nodeName eq "prompt") { 169 192 my ($attr) = $child->attributes; 170 193 my $promptID=$attr->to_literal; 171 my $prompt=$child->to_literal; 172 194 # !!!!!! 195 #my $prompt=$child->to_literal; 196 my @prompts = split (/ /, $child->to_literal); 173 197 print "$promptSelector:"; 174 print $promptID . ":" . $prompt . "\n"; 198 #print $promptID . ":" . $prompt . "\n"; 199 print $promptID . ":"; 200 foreach my $promptWord (@prompts) { 201 if ($promptWord eq $word) { 202 print color("blue"), $promptWord . " " , color("reset"); 203 } else { 204 print $promptWord . " "; 205 } 206 } 207 print "\n"; 208 # !!!!!! 175 209 $$promptSelectorA[$promptSelector] = $promptID; 176 210 $promptSelector++; … … 203 237 204 238 sub playAudio { 205 my ($self,$audioFile)= @_; 206 my $fullpath = "AudioBook/interim_files/missingWordsFolder/" . $audioFile . "-mw.wav"; 239 # !!!!!! 240 #my ($self,$audioFile)= @_; 241 my ($self,$audioFile,$fullpath)= @_; 242 #my $fullpath = "AudioBook/interim_files/missingWordsFolder/" . $audioFile . "-mw.wav"; 243 # !!!!!! 207 244 if (-f $fullpath) { 208 print " \nplaying $audioFile\n";209 $command = ("aplay -q $fullpath"); system($command) == 0 or confess " fullrun$command failed: $?";245 print "playing $audioFile\n"; 246 $command = ("aplay -q $fullpath"); system($command) == 0 or confess "CommandLine.pm $command failed: $?"; 210 247 } else { 211 248 print color("red"), "\ncan't find $fullpath\n", color("reset");