Tryag File Manager
Home
-
Turbo Force
Current Path :
/
home
/
cluster1
/
data
/
bu01
/
1121861
/
html
/
poser
/
Foley programs and data
/
spd24_nahuatl_dat_am
/
Upload File :
New :
File
Dir
//home/cluster1/data/bu01/1121861/html/poser/Foley programs and data/spd24_nahuatl_dat_am/fc2
#!/usr/local/bin/perl5 # -*-perl-*- # # filecutter # # This program finds pauses in a speech file, and generates # small speech files containing isolated words. # # Options # # -s sampling rate (default 16000) # -b sampling bit (default 16) # -S added time [in sec] before and after speech (default -- 0.100) # -p prefix (default stem of input file name) # -v (turn on visual presentation) # # Author: Kazuaki Maeda (maeda@ldc.upenn.edu) # $Id: filecutter,v 1.2 2000/08/14 08:24:25 maeda Exp maeda $ # # Modified by Kevin Foley (kpfoley@ldc.upenn.edu) to output # the start and end times of the small speech files without # generating any (non-temporary) sound files. use Getopt::Std; # default option values $opt_s = 44100; $opt_b = 16; $opt_S = 0.500; $opt_t = 5000; getopts('t:s:b:S:w:r:e:'); $usage = "Usage: filecutter [options] time_file audio_file \t-s sampling rate (default -- 16000) \t-b sampling bit (default -- 16) \t-S added time [in sec] before and after speech (default -- 0.100) \t-p prefix (default -- stem of the input file name) \t-t threshold to discard empty segments (default --- 5000) \t-v (turn on visual presentation) \t-r start time in seconds \t-e end time in seconds \t-w word_id -- the word id number in question\n"; $infile = shift; $timefile = $infile; $infile = shift; if ($infile eq "") { print $usage; exit 1; } else { # print "Input file is $infile\n"; } if ($opt_s) {$sampling_freq = $opt_s;} else {$sampling_freq = 44100}; $errorMargin = 0; $silence = $opt_S; $quantization = $opt_b; $threshold = $opt_t; $prefix = $infile; $prefix =~ s/\.(.*)//; $prefix = $prefix . "-"; $word_id = "unknown"; ### configurable variables $maxtmp = "maxtmp$$.d"; # setmax temp file $tempfile = "tmp$$.sd"; # temp file #$threshold = 4000; # discard temp file if max value is less than this value $max_time = 3; # max time in sec for a cut speech $esps_bin = "/pkg/esps/bin"; # esps directory name $window_size = 10; # window size in secs $silence_req = 100; # pause at least this duration (in msec) ### initialize time file $counter_tf = 0; open (TIMEFILE, "$timefile"); while (<TIMEFILE>) { chomp; @spaced = split; @tabd = split (/\t/); if (/REDO/) { $start_time[$counter_tf] = $spaced[0]; $end_time[$counter_tf] = $spaced[1]; $wordid[$counter_tf] = $tabd[1]; $wordname[$counter_tf] = $tabd[2]; #print "$starttime[$counter_tf]\t$endtime[$counter_tf]\n"; $counter_tf++; } } ### main for ($counter_fc = 0; $counter_fc < $counter_tf; $counter_fc++) { print STDERR "Beginning to segment #$wordid[$counter_fc]\t "; $startSampNum = 0; $baseSampNum = int (($start_time[$counter_fc]+$errorMargin) * $sampling_freq); $endSampNum = int ($window_size * $sampling_freq)+$startSampNum; # $window_size sec later # print "$startSampNum\t$endSampNum\t$sampling_freq\n"; $processedSamples = 0; # samples processed $count = 1; # counter $totalSamples = int (($end_time[$counter_fc]-$start_time[$counter_fc]) * $sampling_freq); $lastSampleNum = int ($end_time[$counter_fc] * $sampling_freq); #print "totalSamples = $totalSamples\n"; # - kf # print "($lastSampleNum - $startSampNum) < $totalSamples )\n"; # while (($baseSampNum + $startSampNum) < $lastSampleNum) { # while (($baseSampNum + $endSampNum)/$sampling_freq < $end_time[$counter_fc]) { while ($startSampNum < $totalSamples) { $endSampNum = $lastSampleNum if ($endSampNum > $lastSampleNum); $startPoint = $baseSampNum + $startSampNum; $endPoint = $baseSampNum + $endSampNum; $startTime = $startPoint/$sampling_freq; $endTime = $endPoint/$sampling_freq; # print "Start2 $startPoint_rename End $endPoint_rename\n"; # print "while: ($baseSampNum + $startSampNum) < $lastSampleNum)\n"; `$esps_bin/copysd -r $startPoint:$endPoint $infile $tempfile`; $out = `$esps_bin/find_ep -x 1 -b 16 $tempfile 2>&1`; unlink($tempfile); # set a potential start point # print "OUT $out\n"; # - kf if ($out =~ /Nonsilence interval analyzed/) { $startSampNum += int(0.5 * $sampling_freq); $endSampNum += int(0.5 * $sampling_freq); $processedSamples += int(0.5 * $sampling_freq); #print "Nonsilence interval analyzed\n"; #print "Shifting...$startSampNum $endSampNum\n"; next; } if ($out =~ /start \((\d+)\)/) { $startSampNum = $1 + $processedSamples; # $startSampNum -= $sampling_freq * $silence; } # set a potential end point if ($out =~ /Nan \((\d+)\)/) { $endSampNum = $1 + $startSampNum + $sampling_freq * $silence; $endSampNum += $sampling_freq * $silence; #print "Start $startSampNum End $endSampNum\n"; } else { $startSampNum += int($window_size * 0.5 * $sampling_freq); $endSampNum += int($window_size * 1.5 * $sampling_freq); $processedSamples += int(0.5 * $sampling_freq); #print "Speech not found between $startTime and $endTime\n"; #print "Shifting...$startSampNum $endSampNum\n"; next; } $startTime = $startSampNum/$sampling_freq; $endTime = $endSampNum/$sampling_freq; if (-f $outfile) {`rm $outfile`;} ##added - kevin $outfile = $prefix.$count++.".d"; #print "using $esps_bin/copysd -r $startSampNum:$endSampNum $infile $outfile\n"; #`$esps_bin/copysd -r $startSampNum:$endSampNum $infile $outfile`; `$esps_bin/copysd -r $startSampNum:$endSampNum $infile $outfile`; `$esps_bin/setmax $outfile $maxtmp`; $out = `$esps_bin/epsps -Da $maxtmp | egrep '^max'`; $out =~ /max_value:\s*(\d+)/; $maxValue = $1; unlink($maxtmp); $startSec = ($baseSampNum + $startSampNum)/$sampling_freq; $endSec = ($baseSampNum + $endSampNum)/$sampling_freq; printf( "%9.3f %9.3f %9.3f\t%s\t%-28s\t%s-%s\t%s\t%s:%s\n", $startSec, $endSec, $endSec - $startSec - 1, $wordid[$counter_fc], $wordname[$counter_fc], $start_time[$counter_fc], $end_time[$counter_fc], $maxValue, $baseSampNum + $startSampNum, $baseSampNum + $endSampNum); print STDERR "."; # if the max value in the window is lower than the threshold, # there is nothing interesting in the window if ($maxValue < $threshold) { # print STDERR "The max sample is too small\n"; # - kf $count--; $startSampNum = $endSampNum; # next start sample number $processedSamples = $endSampNum; $endSampNum += int($window_size * $sampling_freq); # let's look at next window unlink($outfile); next; } #print "Cutting the segment starting at $startTime and ending at $endTime\n"; # - kf $startSampNum = $endSampNum; $processedSamples = $endSampNum; $endSampNum += int($window_size * $sampling_freq); } print STDERR "\n"; }