#!/bin/perl -w use FileHandle; STDOUT->autoflush(1); STDERR->autoflush(1); # time info: ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime ; $mon = $mon + 1 ; # get meeting info $mrget = '/u/tpfau/speech/bin/SUN4/mrget'; # which meeting to run: --------------------------------------------------------- $Session = shift or die "Usage: run-snsdet \n"; $disk = shift or die "Usage: run-snsdet \n"; $Session = lc($Session); $DTS = `$mrget -q -pdts -s $Session`; chomp($DTS); # programs used: --------------------------------------------------------------- # mix soundfiles $jsndmix = "/u/janin/bin/jsndmix"; # create pfiles $createpfiles = "/u/tpfau/speech/bin/SUN4/CreateFeatAndLab"; # create apost files $createapost = "qnsfwd"; # create correlations $runcommand = "run-command "; $createcorrelfiles = "/u/tpfau/speech/bin/SUN4/calcmaxcorreltopzm"; $crosscorrelwinlen = 3200 ; $windowshift = 160 ; $maxcorrelshift = 320 ; # after approximate skew correction! $crosscorrelmin = 0.0 ; # sns detector $snsdetector0 = "/u/tpfau/speech/bin/SUN4/spdtest-v25"; # convert trs to list $trs2list = "/u/tpfau/speech/bin/SUN4/makechunks.pl"; $smoother = "/u/tpfau/speech/bin/SUN4/new_smoother.pl"; # MLP parameters: $modeldir = "/u/tpfau/speech/bin/SUN4/anns/Baseline-Cor-CorShift/"; $mlp_input = 24; $mlp_hidden = 100; $mlp_output = 2; $mlp_weights_file = "sns-22-0-22-2-0-2-100-2-list0.004,0.001,0.0005,0.0005,0.0002,0.0002,0.0001,0.0001-part1-nolapel.weights"; $feat1_start = 0 ; $feat1_num = 22 ; $feat2_start = 0 ; $feat2_num = 2 ; $num_feat_in_file1 = 22 ; $num_feat_in_file2 = 2 ; $lapsession= $Session ; $lapsession .= "_lap" ; # MLP parameters for processing lapel channel: $mlp_weights_file_lapel = "sns-22-0-22-2-0-2-100-2-list0.004,0.001,0.0005,0.0005,0.0002,0.0002,0.0001,0.0001-part1-lapel.weights"; $mlp_hidden_lapel = 100; # find TWO PZM channels (first and third)! @pzmchannels = split(/\s+/, `$mrget -ppzm -q -s $Session`); $nrpzm = 2 ; $pzmfile[0] = "chan$pzmchannels[0].wav"; $pzmfile[1] = "chan$pzmchannels[2].wav"; $pzmcommandend = ""; for( $i=0 ; $i<$nrpzm ; $i++ ) { $pzmcommandend .= "$pzmfile[$i] "; } ; $pzmcommandend .= "$nrpzm"; # paths to current data disks: -------------------------------------------------- $rawshn = "/u/drspeech/data/mr/wavfile/$Session"; $rawwav = "/n/abbott/$disk/drspeech/data/mr/wavfile/raw.wav/$DTS"; $rawbase = "/n/abbott/dd/drspeech/data/mr/wavfile/raw.wav"; $defscfgs = "/u/tpfau/speech/bin/SUN4/defscfgs"; $resultpath = "/n/snapper/scratch/tmp/tpfau/results/$Session"; $tmppath = "/n/snapper/scratch/tmp/tpfau/tmp/$Session"; if(! -d $resultpath ) { mkdir($resultpath, 0770) or die "Couldn't create $resultpath: $!"; `chmod 0770 $resultpath`; } if(! -d $tmppath ) { mkdir($tmppath, 0770) or die "Couldn't create $tmppath: $!"; `chmod 0770 $tmppath`; } if (! -d $rawwav) { mkdir($rawwav, 0770) or die "Couldn't create $rawwav: $!"; `chmod 0770 $rawwav`; } # get channel info (nearfield mikes) @channels = split(/\s+/, `$mrget -pnear -q -s $Session`); $shortch = ""; $longch = ""; $longchreverse = ""; $lapelused = 0 ; $lapelchan = `$mrget -plapel -q -s $Session`; if( $lapelchan eq "no lapel used" || $lapelchan eq "no lapel used\n" ) { $lapelchan = -1 ; } else { $lapelused = 1 ; } chomp($lapelchan); print $lapelchan; print "$Session\n$DTS\n\n"; # expanding wavfiles and gather channel info: ------------------------------------ $numchan=0; foreach $ch (@channels) { if(! -e "$rawwav/chan$ch.wav" ) { print "Expanding chan$ch.wav.shn..."; `sndcat -o $rawwav/chan$ch.wav $rawshn/chan$ch.wav.shn`; print "Done.\n"; } $shortch .= $ch; $longch .= "chan$ch.wav "; $numchan++; } $index = $numchan-1; foreach $ch (@channels) { $longchreverse .= "chan$channels[$index].wav "; $index--; } chdir($rawbase); if(! -l $Session ) { `ln -s $rawwav $Session`; } if(! -l $DTS ) { `ln -s $Session $DTS`; } # mix files: ---------------------------------------------------------------------- chdir($rawwav); if(! -e "mix$shortch.wav" ) { print "\nMixing $longch => mix$shortch.wav ...\n"; print "exec $jsndmix -v -m 8.0 -a -o mix$shortch.wav $longch"; `$jsndmix -v -m 8.0 -a -o mix$shortch.wav $longch`; } # expand some farfield channels (fixed to '6' and 'E') if(! -e "$pzmfile[0]" ) { print "Expand PZM-file $pzmfile[0]\n"; `sndcat -o $pzmfile[0] $rawshn/$pzmfile[0].shn`; } if(! -e "$pzmfile[1]" ) { print "Expand PZM-file $pzmfile[1]\n"; `sndcat -o $pzmfile[1] $rawshn/$pzmfile[1].shn`; } # check, which files already exist: --------------------------------------------- $pfileexist = 1; foreach $ch (@channels) { if(! -e "$tmppath/chan$ch.wav.pfile" ) { $pfileexist = 0; } } $correlexist = 1; foreach $ch (@channels) { if(! -e "$tmppath/chan$ch.correl" ) { $correlexist = 0; } } $apostexist = 1; foreach $ch (@channels) { if(! -e "$tmppath/chan$ch.wav.apost" ) { $apostexist = 0; } } $apostlapelexist = 1; foreach $ch (@channels) { if(! -e "$tmppath/chan$ch.wav.apost-lapel" ) { $apostlapelexist = 0; } } # create pfiles: ------------------------------------------------------------------- if( !$apostexist || !$apostlapelexist ) { if( ! $pfileexist ) { # parameters for cutting features out of feature file: $feat_range = "0,1,4-23" ; print "Create pfiles ...\n"; $pfilecommand = "$runcommand $createpfiles $defscfgs/akupre-createpfile-nolabels.cfg $tmppath $longch "; foreach $ch (@channels) { $pfilecommand .= "$defscfgs/dummy.trs "; } $pfilecommand .= "mix$shortch.wav $pzmcommandend"; print "exec $pfilecommand\n"; `$pfilecommand`; } else { # check, how many features? that's not really a good solution! $num_feat_pfile = 0 ; # assume, pfiles contain relevant features only: $feat_range = "0-"; # can we really trust that assunption? No, so better check pfiles! foreach $ch (@channels) { $command = "pfile_info -i $tmppath/chan$ch.wav.pfile" ; @info = split( / /, `$command` ) ; if( $info[6] != $feat1_num ) { # the pfiles contain more then we want: cut out relevant info $feat_range = "0,1,4-23" ; last ; } # end if } # end foreach } # end else ( !$pfileexist) # create correl files: ------------------------------------------------------------- # create correlfiles (correlations with pzm signals!) if( ! $correlexist ) { # 1) create list of commands: open( COMMANDLIST, ">$tmppath/commandlist-correl-$sec-$min-$hour-$mday-$mon-$year" ); # 2) write commands for all channels into commandlist print( "Create Correl Files with PZM signals\n" ) ; foreach $ch (@channels) { $command = "$createcorrelfiles chan$ch.wav $tmppath $crosscorrelwinlen $windowshift $maxcorrelshift $crosscorrelmin $pzmcommandend\n"; print( COMMANDLIST "$command" ); #`$command`; } # 3) close file close( COMMANDLIST ); # 4) execute commands in commandlist: $command = "$runcommand -J $numchan -f $tmppath/commandlist-correl-$sec-$min-$hour-$mday-$mon-$year\n"; print( "exec $command\n" ) ; `$command`; #system( "rm commandlist-correl-$sec-$min-$hour-$mday-$mon-$year" ); } # get length of correl and feature files, cut all files to length of shortest file: # and select, whcih features are wanted!!!! # how long are the created feature and correl files? print "Get Length of Feature and Correl Files:\n" ; $minlen = 10000000 ; foreach $ch (@channels) { $command = "pfile_info $tmppath/chan$ch.wav.pfile\n"; @info = split( / /, `$command` ) ; if( $info[2] < $minlen ) { $minlen = $info[2] ; } $command = "pfile_info $tmppath/chan$ch.correl\n"; @info = split( / /, `$command` ) ; if( $info[2] < $minlen ) { $minlen = $info[2] ; } } $lastframe = $minlen-1; print( "shortest feature or correl file has $minlen frames\n" ); # cut all files: -------------------------------------------------------------------- foreach $ch (@channels) { $command = "pfile_concat -fr $feat_range -o $tmppath/chan$ch-cut.wav.pfile -pr 0-$lastframe $tmppath/chan$ch.wav.pfile\n"; print( "exec $command" ); `$command`; $command = "mv $tmppath/chan$ch-cut.wav.pfile $tmppath/chan$ch.wav.pfile\n"; print( "exec $command" ); `$command`; $command = "pfile_concat -o $tmppath/chan$ch-cut.correl -pr 0-$lastframe $tmppath/chan$ch.correl\n"; print( "exec $command" ); `$command`; $command = "mv $tmppath/chan$ch-cut.correl $tmppath/chan$ch.correl\n"; print( "exec $command" ); `$command`; } ; } # create apost files: --------------------------------------------------------------- # 1) create list of commands: open( COMMANDLIST, ">$tmppath/commandlist-apost-$sec-$min-$hour-$mday-$mon-$year" ); # 2) write commands for all channels into commandlist foreach $ch (@channels) { if(! -e "$tmppath/chan$ch.wav.apost" ) { print "Create file with posteriors chan$ch.wav.apost ...\n"; # create posteriors with 'standard' net $apostcommand = ""; $apostcommand = "$createapost ftr1_file=$tmppath/chan$ch.wav.pfile ftr1_format=pfile ftr2_file=$tmppath/chan$ch.correl ftr2_format=pfile ftr1_width=$num_feat_in_file1 ftr2_width=$num_feat_in_file2 ftr1_ftr_start=$feat1_start ftr1_ftr_count=$feat1_num ftr2_ftr_start=$feat2_start ftr2_ftr_count=$feat2_num ftr1_window_len=1 ftr2_window_len=1 ftr1_window_offset=0 ftr2_window_offset=0 unary_window_offset=0 window_extent=1 fwd_sent_range=0 mlp3_input_size=$mlp_input mlp3_hidden_size=$mlp_hidden mlp3_output_size=$mlp_output mlp3_output_type=softmax verbose=true activation_file=$tmppath/chan$ch.wav.apost activation_format=pfile init_weight_file=$modeldir/$mlp_weights_file\n"; print( COMMANDLIST "$apostcommand" ); } if(! -e "$tmppath/chan$ch.wav.apost-lapel" ) { # in addition create posteriors with 'lapel' net $apostcommandlapel = ""; $apostcommandlapel = "$createapost ftr1_file=$tmppath/chan$ch.wav.pfile ftr1_format=pfile ftr2_file=$tmppath/chan$ch.correl ftr2_format=pfile ftr1_width=$num_feat_in_file1 ftr2_width=$num_feat_in_file2 ftr1_ftr_start=$feat1_start ftr1_ftr_count=$feat1_num ftr2_ftr_start=$feat2_start ftr2_ftr_count=$feat2_num ftr1_window_len=1 ftr2_window_len=1 ftr1_window_offset=0 ftr2_window_offset=0 unary_window_offset=0 window_extent=1 fwd_sent_range=0 mlp3_input_size=$mlp_input mlp3_hidden_size=$mlp_hidden_lapel mlp3_output_size=$mlp_output mlp3_output_type=softmax verbose=true activation_file=$tmppath/chan$ch.wav.apost-lapel activation_format=pfile init_weight_file=$modeldir/$mlp_weights_file_lapel\n"; print( COMMANDLIST "$apostcommandlapel" ); } } # 3) close file close( COMMANDLIST ); # 4) execute commands in commandlist: $command = "$runcommand -J $numchan -f $tmppath/commandlist-apost-$sec-$min-$hour-$mday-$mon-$year\n"; print( "exec $command\n" ) ; `$command`; # was there a lapel mic used? if( $lapelused == 1 ) { $command = "cp $tmppath/chan'$lapelchan'.wav.apost $tmppath/chan$lapelchan.wav.apost_saved"; `$command`; $command = "cp $tmppath/chan$lapelchan.wav.apost-lapel $tmppath/chan$lapelchan.wav.apost"; `$command`; } ; # run detector: --------------------------------------------------------------------- @speechfirst = ("0.5") ; @speechsecond = ("0.1") ; foreach $first (@speechfirst) { foreach $second (@speechsecond) { $resultfile0 = "$resultpath/$Session-forasr-time60" ; if( ! -e "$resultfile0" ) { print "Run S/NS detection (version0: single net, twopass) ...\n"; $detcommand = ""; $detcommand = "$runcommand $snsdetector0 $defscfgs/akupre-det-v25-twopass-time60.cfg $defscfgs/spnonsp-chan-det-1stpass-v25-$first-0.5.cfg $defscfgs/spnonsp-chan-det-2ndpass-v25-$second-0.25.cfg $tmppath $longch $resultfile0 $pzmcommandend" ; print "exec $detcommand\n"; `$detcommand`; } else { print "$resultfile0 already exists\n"; } } } `cp $defscfgs/akupre-det-v25-twopass-time60.cfg $resultpath/`; `cp $defscfgs/spnonsp-chan-det-1stpass-v25-$first-0.5.cfg $resultpath/`; `cp $defscfgs/spnonsp-chan-det-2ndpass-v25-$second-0.25.cfg $resultpath/`; # was there a lapel mic used? if( $lapelused == 1 ) { $command = "mv $tmppath/chan$lapelchan.wav.apost_saved $tmppath/chan$lapelchan.wav.apost"; `$command`; } ; # remove pfiles, apost-files, cfg-files print "remove feature files\n"; `rm $tmppath/*.pfile`; if( !$apostexist ) { print "remove posterior files\n"; `rm $tmppath/*.apost`; print "remove posterior files\n"; `rm $tmppath/*.apost_saved`; print "remove lapel posteriors files\n"; `rm $tmppath/*.apost-lapel`; } print "remove correl files\n"; `rm $tmppath/*.correl`; print "remove commandlists for creating pfiles\n"; `rm $tmppath/command*`; print "remove trs-files of indiv channels\n"; `rm $resultpath/*.?.trs`; # move results #`mv $Session-$DTS-auto* $resultpath`; print "Done.\n\n";