voxforge.org
VoxForge Dev
Show
Ignore:
Timestamp:
06/18/08 21:42:49 (6 months ago)
Author:
kmaclean
Message:

AudioSegmentation script - snapshot re: interactive Missingword update

Files:

Legend:

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

    r2614 r2615  
    4747        $self->{'term'} = Term::ReadLine->new("Missing_Word_Processing");        
    4848         
    49         $self->{'promptSelectorA'} = []; 
    50         $self->{'phoneSelectorA'} = [];  
     49        # !!!!!! 
     50        #$self->{'promptSelectorA'} = []; 
     51        #$self->{'phoneSelectorA'} = [];         
     52        # !!!!!! 
    5153        return $self; 
    5254} 
     
    6466        my $doc = $self->{'doc'}; 
    6567 
    66         print "VoxForge Missing Word processing (q to quit)\n"; 
     68        print "VoxForge Missing Word processing (\$ to quit)\n"; 
    6769        print "(enter \"^\" to go back one entry)\n"; 
    6870        print "--------------------------------------------\n"; 
     
    8991                } 
    9092        } 
    91  
    9293        updateDictionary(\@processedWordsPhones); 
    9394} 
     
    101102sub process{ 
    102103        my ($self,$wordRef,$wordNumber,$processedWordsPhones,$totalNumberOfWords)= @_; 
     104        # !!!!!! 
     105        $self->{'promptSelectorA'} = []; 
     106        $self->{'phoneSelectorA'} = [];  
     107        # !!!!!! 
    103108        my $promptSelectorA = $self->{'promptSelectorA'}; 
    104109        my $phoneSelectorA = $self->{'phoneSelectorA'}; 
    105          
     110 
    106111        my $doc = $self->{'doc'}; 
    107112        my $term= $self->{'term'}; 
     
    113118        $self->displayChildNodes($wordRef,$wordNumber,$totalNumberOfWords); 
    114119        while (defined(my $line=$term->readline($prompt,$preput))) { # get command from user     
    115                 if ($line eq 'q') { 
     120                if ($line eq '$') { 
    116121                        exit; 
    117                 } elsif ($line =~ /^\d+$/) { # digit 
    118                         $self->displayChildNodes($wordRef,$wordNumber,$totalNumberOfWords); 
     122                } elsif ($line =~ /^\d+$/) { # one or more numbers 
     123                        #$self->displayChildNodes($wordRef,$wordNumber,$totalNumberOfWords); 
    119124                        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";                      
    123144                        }        
    124145                } elsif ($line =~ /^[A-Za-z]$/) { # one letter  
    125                         $self->displayChildNodes($wordRef,$wordNumber,$totalNumberOfWords); 
     146                        #$self->displayChildNodes($wordRef,$wordNumber,$totalNumberOfWords); 
    126147                        my $asciiOfFirstCharacter = ord($line); 
    127148                        if (($asciiOfFirstCharacter >= 97 ) and ($asciiOfFirstCharacter < @$phoneSelectorA)) { 
    128149                                $preput = $$phoneSelectorA[$asciiOfFirstCharacter];      
    129150                        } 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";                              
    131153                        }        
    132154                } elsif ($preput) { # phoneme set selected by user 
    133155                        $$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"; 
    135158                        return "next"; 
    136159                }  elsif ($line eq '^') { # back one 
     
    141164                } else { 
    142165                        $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"); 
    144167                } 
    145168        } 
     
    163186        my @childNodes = $wordRef->childNodes;   
    164187                 
    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");                    
    167190        foreach my $child (@childNodes) { 
    168191                if ($child->nodeName eq "prompt") { 
    169192                my ($attr) = $child->attributes; 
    170193                        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); 
    173197                        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                # !!!!!! 
    175209                        $$promptSelectorA[$promptSelector] = $promptID;                          
    176210                        $promptSelector++;       
     
    203237 
    204238sub 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        # !!!!!! 
    207244        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: $?"; 
    210247        } else { 
    211248                print color("red"), "\ncan't find $fullpath\n", color("reset");