Blame view

tools/sctk-2.4.10/bin/spkr2sad.pl 1002 Bytes
8dcb6dfcb   Yannick Estève   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
  #!/usr/bin/perl -w
  
  use strict;
  use Data::Dumper;
  
  my $time = 0.3;
  my %data = ();
  while (<>){
      my @a = split;
      if ($_ =~ /^;/){
  	print;
  	next;
      }
      push @{ $data{$a[1]}{$a[0]} }, \@a;
  }
  #print Dumper(\%data);
  my $max;
  foreach my $file(sort (keys %data)){
      if (exists($data{$file}{"SPKR-INFO"})){
  	my @d = @{ $data{$file}{"SPKR-INFO"} };
  	$d[0]->[7] = "speech";
  	$d[0]->[6] = "unknown";
  	print join(" ",@{ $d[0] })."
  ";
      } else {
  	die "Error: No SPKR-INFO and no SPEAKER Tags" if (! exists($data{$file}{"SPEAKER"}));
  	# Copy a SPEAKER line
  	my @a = ();
  	foreach my $e( @{ $data{$file}{"SPEAKER"}[0] }){
  	    push @a, $e;
  	}
  	$a[0] = "SPKR-INFO";
  	$a[3] = "<NA>";
  	$a[4] = "<NA>";
  	$a[5] = "<NA>";
  	$a[6] = "unknown";
  	$a[7] = "speech";
  	print join(" ",@a)."
  ";
      }
      if (exists($data{$file}{"SPEAKER"})){
  	my @d = sort {$a->[3] <=> $b->[3]} @{ $data{$file}{"SPEAKER"} };
  	for (my $i=0; $i<@d ; $i++){
  	    $d[$i]->[7] = "speech";
  	    print join(" ",@{ $d[$i] })."
  ";
  	}
      }
  }