Blame view
tools/sctk-2.4.10/src/rttmSmooth/rttmSmooth.pl
1.64 KB
8dcb6dfcb first commit |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
#!/usr/bin/perl -w # History: # v0 - initial version # v1 - Smooth IFF the gap is <= the threshold # v2 - echo out all lines # - IF $argv[0] is defined, it's the smooth time use strict; use Data::Dumper; use Getopt::Long; my $time = 0.3; my $result = GetOptions ("s=s" => \$time); die "Error " if (! $result); my %data = (); while (<STDIN>){ if ($_ =~ /^;/){ print; next; } my @a = split; push @{ $data{$a[1]." ".$a[7]}{$a[0]} }, \@a; } #print Dumper(\%data); #exit; my $max; foreach my $file(sort (keys %data)){ # print "PRocess $file "; my @d; foreach my $key(keys %{ $data{$file} }){ next if ($key eq "SPEAKER"); @d = @{ $data{$file}{$key} }; for (my $i=0; $i<@d; $i++){ print join(" ",@{ $d[$i] })." "; } } next if (! exists($data{$file}{"SPEAKER"} )); @d = sort {$a->[3] <=> $b->[3]} @{ $data{$file}{"SPEAKER"} }; for (my $i=0; $i<@d - 1; $i++){ # print " ".join(" ",@{ @d[$i] })." "; # die "Error: Segments from the same speaker overlap. ". # join(" $i: ", @{$d[$i]}). " ".($i+1)." " join(" ".@{ $d[$i]}) # if ($d[$i]->[3] + $d[$i]->[4] > $d[$i+1]->[3]); if ($d[$i]->[3] + $d[$i]->[4] >= $d[$i+1]->[3] - $time){ # print " Smooth with next ".($d[$i]->[3] + $d[$i]->[4])." with ",( $d[$i+1]->[3] - $time)." "; $max = $d[$i]->[3] + $d[$i]->[4]; $max = $d[$i+1]->[3] + $d[$i+1]->[4] if ($max < $d[$i+1]->[3] + $d[$i+1]->[4]); $d[$i]->[4] = sprintf("%.3f",$max - $d[$i]->[3]); splice (@d, $i+1, 1); # print " Replaced with ".join(" ",@{ @d[$i] })." "; $i--; } } for (my $i=0; $i<@d; $i++){ print join(" ",@{ $d[$i] })." "; } } |