Blame view

egs/voxceleb/v1/local/make_voxceleb2.pl 2.22 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
  #!/usr/bin/perl
  #
  # Copyright 2018  Ewald Enzinger
  #
  # Usage: make_voxceleb2.pl /export/voxceleb2 dev data/dev
  #
  # Note: This script requires ffmpeg to be installed and its location included in $PATH.
  
  if (@ARGV != 3) {
    print STDERR "Usage: $0 <path-to-voxceleb2> <dataset> <path-to-data-dir>
  ";
    print STDERR "e.g. $0 /export/voxceleb2 dev data/dev
  ";
    exit(1);
  }
  
  # Check that ffmpeg is installed.
  if (`which ffmpeg` eq "") {
    die "Error: this script requires that ffmpeg is installed.";
  }
  
  ($data_base, $dataset, $out_dir) = @ARGV;
  
  if ("$dataset" ne "dev" && "$dataset" ne "test") {
    die "dataset parameter must be 'dev' or 'test'!";
  }
  
  opendir my $dh, "$data_base/$dataset/aac" or die "Cannot open directory: $!";
  my @spkr_dirs = grep {-d "$data_base/$dataset/aac/$_" && ! /^\.{1,2}$/} readdir($dh);
  closedir $dh;
  
  if (system("mkdir -p $out_dir") != 0) {
    die "Error making directory $out_dir";
  }
  
  open(SPKR, ">", "$out_dir/utt2spk") or die "Could not open the output file $out_dir/utt2spk";
  open(WAV, ">", "$out_dir/wav.scp") or die "Could not open the output file $out_dir/wav.scp";
  
  foreach (@spkr_dirs) {
    my $spkr_id = $_;
  
    opendir my $dh, "$data_base/$dataset/aac/$spkr_id/" or die "Cannot open directory: $!";
    my @rec_dirs = grep {-d "$data_base/$dataset/aac/$spkr_id/$_" && ! /^\.{1,2}$/} readdir($dh);
    closedir $dh;
  
    foreach (@rec_dirs) {
      my $rec_id = $_;
  
      opendir my $dh, "$data_base/$dataset/aac/$spkr_id/$rec_id/" or die "Cannot open directory: $!";
      my @files = map{s/\.[^.]+$//;$_}grep {/\.m4a$/} readdir($dh);
      closedir $dh;
  
      foreach (@files) {
        my $name = $_;
        my $wav = "ffmpeg -v 8 -i $data_base/$dataset/aac/$spkr_id/$rec_id/$name.m4a -f wav -acodec pcm_s16le -|";
        my $utt_id = "$spkr_id-$rec_id-$name";
        print WAV "$utt_id", " $wav", "
  ";
        print SPKR "$utt_id", " $spkr_id", "
  ";
      }
    }
  }
  close(SPKR) or die;
  close(WAV) or die;
  
  if (system(
    "utils/utt2spk_to_spk2utt.pl $out_dir/utt2spk >$out_dir/spk2utt") != 0) {
    die "Error creating spk2utt file in directory $out_dir";
  }
  system("env LC_COLLATE=C utils/fix_data_dir.sh $out_dir");
  if (system("env LC_COLLATE=C utils/validate_data_dir.sh --no-text --no-feats $out_dir") != 0) {
    die "Error validating directory $out_dir";
  }