voxforge.org
VoxForge Dev

Changeset 2572

Show
Ignore:
Timestamp:
05/07/08 23:12:58 (8 months ago)
Author:
kmaclean
Message:

AudioSegmentation scripts directory restructure

Files:

Legend:

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

    r2565 r2572  
    3434use AudioBook::Dictionary; 
    3535#################################################################### 
     36### Options 
     37#################################################################### 
    3638our($opt_a, $opt_t,$opt_d,$opt_T); # need to define these because using strict. 
    3739getopt('atdt');    #  sets $opt_* as a side effect. 
     
    5153print "testfile:$textfile\n"; 
    5254print "voxforgeDict:$voxforgeDict\n"; 
     55#################################################################### 
     56### Class Variables 
     57#################################################################### 
    5358my $command; 
     59my %parms; 
     60$parms{'debug'} = 0; 
     61$parms{'g2p_model'} = "AudioBook/input_files/g2p/models/model-5"; 
     62$parms{'htk_files'} = "AudioBook/input_files/htk"; 
     63         
    5464#################################################################### 
    5565### Main 
    5666#################################################################### 
    57 my $textContents = AudioBook::Text->new($textfile); 
    58 $textContents->createWLISTFile("interim_files/wlist"); 
    59 my $dictionary = AudioBook::Dictionary->new($voxforgeDict); 
    60 my $missingwordfound = $dictionary->findOutOfVocabularyWords("interim_files/MissingWords"); 
     67my $textContents = AudioBook::Text->new(\%parms,$textfile); 
     68$textContents->createWLISTFile("AudioBook/interim_files/wlist"); 
     69my $dictionary = AudioBook::Dictionary->new(\%parms,$voxforgeDict); 
     70my $missingwordfound = $dictionary->findOutOfVocabularyWords("AudioBook/interim_files/MissingWords"); 
    6171if ($missingwordfound) {  
    62         $dictionary->getPronunciations("interim_files/MissingWords_out"); # uses g2p 
     72        $dictionary->getPronunciations("AudioBook/interim_files/MissingWords_out"); # uses g2p 
    6373        $dictionary->updatePronDict(); 
    6474        # need to update dict with missing words 
    65         $command = ("HDMan -A -D -T 1 -g htk/global.ded -m -w interim_files/wlist -i -l interim_files/dlog interim_files/dict $voxforgeDict"); system($command) == 0 or confess "fullrun $command failed: $?";  
     75        my $htk_files = $parms{'htk_files'}; 
     76        $command = ("HDMan -A -D -T 1 -g $htk_files/global.ded -m -w AudioBook/interim_files/wlist -i -l AudioBook/interim_files/dlog AudioBook/interim_files/dict $voxforgeDict"); system($command) == 0 or confess "fullrun $command failed: $?";  
    6677}  
    67 #$command = ("perl fullrun/htksegment.pl interim_files/$file_name $samplingRate"); print "$command\n"; system($command) == 0 or confess "fullrun $command failed: $?"; 
    68 my $audio = AudioBook::Audio->new($audiofile,$textContents); 
     78my $audio = AudioBook::Audio->new(\%parms,$audiofile,$textContents); 
    6979$audio->segment(); 
    7080print "completed!\n";  
  • Trunk/Scripts/Audio_scripts/AudioSegmentation/AudioBook/Audio.pm

    r2570 r2572  
    5151#################################################################### 
    5252sub new { 
    53         my ($class,$audiofile,$textContents) = @_;  
     53        my ($class,$parms,$audiofile,$textContents) = @_;  
    5454        print "Audio\.pm:audiofile:$audiofile\n"; 
    55         $command = ("rm -f interim_files/wav/*.wav"); print "$command\n"; system($command) == 0 or confess "Audio.pm $command failed: $?"; 
     55        $command = ("rm -f AudioBook/output_files/wav/*.wav"); print "$command\n"; system($command) == 0 or confess "Audio.pm $command failed: $?"; 
    5656         
    5757        my %self; 
    58         $self{"debug"} = 0; 
     58        $self{"parms"} = $parms;        
    5959        $self{"process_audio"} = 1; 
    6060        $self{"filename"} = $audiofile; 
     
    8484        my ($self,$textContents) = @_;   
    8585        my $filename = $self->{"filename"}; 
     86        my $htk_files = $self->{'parms'}->{'htk_files'}; 
    8687         
    8788        # Hvite only works with 16kHz sampling rate audio 
    88         $command = ("sox $filename -c 1 -r 16000 -w interim_files/downsampled.wav"); print "$command\n"; system($command) == 0 or confess "fullrun $command failed: $?"; 
     89        $command = ("sox $filename -c 1 -r 16000 -w AudioBook/interim_files/downsampled.wav"); print "$command\n"; system($command) == 0 or confess "fullrun $command failed: $?"; 
    8990        # create mlf file  
    90         $textContents->createMLFFile("downsampled","interim_files/words.mlf" ); 
     91        $textContents->createMLFFile("downsampled","AudioBook/interim_files/words.mlf" ); 
    9192        # forced alignment - creates aligned.out 
    92         $command = ("cd interim_files && HVite -A -D -T 1 -l '*'  -a -b SENT-END -m -C ../htk/wav_config -H ../htk/macros -H ../htk/hmmdefs -m -t 250.0 150.0 1000.0 -I words.mlf  -i aligned.out -S ../htk/train.scp dict ../htk/tiedlist"); system($command) == 0 or confess "error: $command failed: $?"; 
     93#!!!!!! $command = ("cd AudioBook/interim_files && HVite -A -D -T 1 -l '*'  -a -b SENT-END -m -C wav_config -H macros -H hmmdefs -m -t 250.0 150.0 1000.0 -I words.mlf  -i aligned.out -S train.scp dict tiedlist"); system($command) == 0 or confess "error: $command failed: $?"; 
     94        $command = ("pwd && HVite -A -D -T 1 -l '*' -a -b SENT-END -m -C $htk_files/wav_config -H $htk_files/models/macros -H $htk_files/models/hmmdefs -m -t 250.0 150.0 1000.0 -I AudioBook/interim_files/words.mlf  -i AudioBook/interim_files/aligned.out -S $htk_files/train.scp AudioBook/interim_files/dict $htk_files/models/tiedlist"); system($command) == 0 or confess "error: $command failed: $?"; 
     95 
    9396} 
    9497 
    9598sub _processHViteOutput { # private 
    9699        my ($self) = @_;         
    97          
    98         open(ALIGNED, "<interim_files/aligned.out") or confess ("can\'t open interim_files/aligned.out file for reading");  
     100                
     101        open(ALIGNED, "<AudioBook/interim_files/aligned.out") or confess ("can\'t open AudioBook/interim_files/aligned.out file for reading");  
    99102        my @aligned = <ALIGNED>; 
    100103        close ALIGNED; 
     
    123126                }        
    124127        } 
    125         open(LOG, ">interim_files/htksegment_log") or confess ("cannot open htksegment_log for output");       
     128        open(LOG, ">AudioBook/interim_files/htksegment_log") or confess ("cannot open htksegment_log for output");     
    126129        foreach my $line (@aligned_words) { 
    127130                print LOG "$line\n"; 
     
    142145        print "### segment::$filename #################################################################\n";      
    143146        # copy to "interim_files"" directory for processing; also converts to 16 bits per sample (-w=16-bits) so it can be processed by HVite 
    144         $command = ("sox $filename -w interim_files/$filename_nopath"); print "$command\n"; system($command) == 0 or confess "fullrun $command failed: $?";  
     147        $command = ("sox $filename -w AudioBook/interim_files/$filename_nopath"); print "$command\n"; system($command) == 0 or confess "fullrun $command failed: $?";  
    145148         
    146149        my $loop; 
     
    154157        my @aligned_line = split(/ /,$$aligned_words[$sentence_end]); 
    155158        my ($word,$startTime,$endTime,$pause) = @aligned_line;   
    156         open(PROMPTS, ">interim_files/wav/prompts") or confess ("cannot open interim_files/wav/prompts for output");   
     159        open(PROMPTS, ">AudioBook/output_files/prompts") or confess ("cannot open AudioBook/output_files/prompts for output");         
    157160        while (!$lastSentence) { 
    158161                $loop++; 
     
    187190        } 
    188191         
    189         $command = ("rm interim_files/wav/temp.wav"); print "cmd:$command\n" if $debug; system($command); 
     192        $command = ("rm AudioBook/interim_files/wav/temp.wav"); print "cmd:$command\n" if $debug; system($command); 
    190193        print "### segment summary: #################################################################\n";         
    191194        print "\nSentence Length: min:$min_sentence_length_linenumber->$min_sentence_length_found; max:$max_sentence_length_linenumber->$max_sentence_length_found\n"; 
     
    194197                print "\t$line\n"; 
    195198        }        
     199        $command = ("mv AudioBook/interim_files/dict AudioBook/output_files"); print "cmd:$command\n" if $debug; system($command);       
     200        $command = ("mv AudioBook/interim_files/MissingWords_out AudioBook/output_files/MissingWords_pron"); print "cmd:$command\n" if $debug; system($command);         
    196201} 
    197202 
     
    323328        my $filename_nosuffix = $self->{"filename_nosuffix"}; 
    324329        my $filename_nopath = $self->{"filename_nopath"}; 
     330        my $htk_files = $self->{'parms'}->{'htk_files'}; 
    325331 
    326332        #print "debug:$debug;process_audio:$process_audio:\n"; 
     
    330336                # use TARGETKIND=NOHEAD in HCopy command to remove 'click' noise that HCopy puts at the very beginning of each file it creates 
    331337                # make sure you use NATURALWRITEORDER = T and NATURALREADORDER = T      in the HTK config file   
    332                 $command = ("HCopy -C htk/copy_config  -s $startTime -e $endTime interim_files/$filename_nopath interim_files/wav/temp.wav"); print "cmd:$command\n" if $debug; system($command);  
     338                $command = ("HCopy -C $htk_files/copy_config  -s $startTime -e $endTime AudioBook/interim_files/$filename_nopath AudioBook/interim_files/temp.wav"); print "cmd:$command\n" if $debug; system($command);  
    333339                # sox command to create a proper wav file with a RIFF header;  
    334                 $command = ("sox  -t .raw -r $samplerate -sw interim_files/wav/temp.wav interim_files/wav/$filename_nosuffix$padded_fileid.wav"); print "cmd:$command\n" if $debug; system($command);          
    335                 print "interim_files/wav/$filename_nosuffix$padded_fileid.wav\n" if not $debug; 
     340                $command = ("sox  -t .raw -r $samplerate -sw AudioBook/interim_files/temp.wav AudioBook/output_files/wav/$filename_nosuffix$padded_fileid.wav"); print "cmd:$command\n" if $debug; system($command);   
     341                print "AudioBook/output_files/wav/$filename_nosuffix$padded_fileid.wav\n" if not $debug; 
    336342        } else { 
    337                 print "interim_files/wav/$filename_nosuffix$padded_fileid.wav\t$startTime:$endTime:\n" if $debug; 
     343                print "AudioBook/output_files/wav/$filename_nosuffix$padded_fileid.wav\t$startTime:$endTime:\n" if $debug; 
    338344        } 
    339345} 
  • Trunk/Scripts/Audio_scripts/AudioSegmentation/AudioBook/Dictionary.pm

    r2564 r2572  
    3232#################################################################### 
    3333sub new { 
    34         my ($class,$voxforgeDict) = @_;  
     34        my ($class,$parms,$voxforgeDict) = @_;  
    3535        my %self; 
     36        $self{"parms"} = $parms; 
    3637        $self{"voxforgeDict"} = $voxforgeDict; 
    3738        bless(\%self,$class); 
     
    4445        my ($self,$missing_words)= @_;   
    4546        my $voxforgeDict = $self->{"voxforgeDict"};  
     47        my $htk_files = $self->{'parms'}->{'htk_files'}; 
     48         
    4649        $self->{"missing_words"} = $missing_words; 
    47          
    48         $command = ("HDMan -A -D -T 1 -g htk/global.ded -m -w interim_files/wlist -i -l interim_files/dlog interim_files/dict $voxforgeDict"); system($command) == 0 or confess "fullrun $command failed: $?";  
    49         open(DLOG,"interim_files/dlog") or confess ("cannot open interim_files/dlog file"); 
     50         
     51        $command = ("HDMan -A -D -T 1 -g $htk_files/global.ded -m -w AudioBook/interim_files/wlist -i -l AudioBook/interim_files/dlog AudioBook/interim_files/dict $voxforgeDict"); system($command) == 0 or confess "fullrun $command failed: $?";  
     52        open(DLOG,"AudioBook/interim_files/dlog") or confess ("cannot open AudioBook/interim_files/dlog file"); 
    5053        open(MISSINGWORDS,">$missing_words") or confess ("cannot open $missing_words file"); 
    5154        my $missingwordsheader = 0; 
     
    7679        my ($self,$missing_words_out)= @_;       
    7780        $self->{"missing_words_out"} = $missing_words_out; 
     81        my $model = $self->{'parms'}->{'g2p_model'}; 
    7882        my $missing_words = $self->{"missing_words"}; 
    7983         
    8084        my @missingwords = `export PYTHONPATH=/usr/local/lib64/python2.4/site-packages && 
    81                             g2p.py --model g2p/models/model-5 --apply $missing_words`; 
     85                            g2p.py --model $model --apply $missing_words`; 
    8286        if ($?) { 
    8387            confess "g2p.py $command failed: $?"; 
  • Trunk/Scripts/Audio_scripts/AudioSegmentation/AudioBook/Text.pm

    r2568 r2572  
    3131#################################################################### 
    3232sub new { 
    33         my ($class,$inputfilename) = @_;  
     33        my ($class,$parms,$inputfilename) = @_;  
    3434        my %self; 
     35        $self{"parms"} = $parms; 
    3536        $self{"inputfilename"} = $inputfilename; 
    3637        _clean(\%self); 
     
    118119        open(MLF, ">$MLFFile") or confess ("cannot open words.mlf for output"); 
    119120        print MLF "#!MLF!#\n"; #  
    120         print MLF "\"$wavfilename.lab\"\n"; 
     121        print MLF "\"AudioBook/interim_files/$wavfilename.lab\"\n"; 
    121122        foreach my $word (@$words) { 
    122123                print MLF "$word\n"; 
  • Trunk/Scripts/Audio_scripts/AudioSegmentation/AudioBook/input_files/htk/train.scp

    r2553 r2572  
    1 downsampled.wav 
     1AudioBook/interim_files/downsampled.wav 
  • Trunk/Scripts/Audio_scripts/AudioSegmentation/AudioBook/interim_files/dlog

    r2570 r2572  
    5555 43. th    :     1 
    5656 
    57 Dictionary interim_files/dict created 
     57Dictionary AudioBook/interim_files/dict created 
  • Trunk/Scripts/Audio_scripts/AudioSegmentation/AudioBook/interim_files/words.mlf

    r2570 r2572  
    11#!MLF!# 
    2 "downsampled.lab" 
     2"AudioBook/interim_files/downsampled.lab" 
    33THOSE 
    44EVENING