Blame view

Scripts/steps/make_mfcc.sh 3.05 KB
ec85f8892   bigot benjamin   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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
  #!/bin/bash 
  
  # Copyright 2012  Johns Hopkins University (Author: Daniel Povey)
  # Apache 2.0
  # To be run from .. (one directory up from here)
  # see ../run.sh for example
  
  # Begin configuration section.
  nj=4
  cmd=run.pl
  mfcc_config=conf/mfcc.conf
  # End configuration section.
  
  echo "$0 $@"  # Print the command line for logging
  
  if [ -f path.sh ]; then . ./path.sh; fi
  . parse_options.sh || exit 1;
  
  if [ $# != 3 ]; then
     echo "usage: make_mfcc.sh [options] <data-dir> <log-dir> <path-to-mfccdir>";
     echo "options: "
     echo "  --mfcc-config <config-file>                      # config passed to compute-mfcc-feats "
     echo "  --nj <nj>                                        # number of parallel jobs"
     echo "  --cmd (utils/run.pl|utils/queue.pl <queue opts>) # how to run jobs."
     exit 1;
  fi
  
  data=$1
  logdir=$2
  mfccdir=$3
  
  
  # make $mfccdir an absolute pathname.
  mfccdir=`perl -e '($dir,$pwd)= @ARGV; if($dir!~m:^/:) { $dir = "$pwd/$dir"; } print $dir; ' $mfccdir ${PWD}`
  
  # use "name" as part of name of the archive.
  name=`basename $data`
  
  mkdir -p $mfccdir || exit 1;
  mkdir -p $logdir || exit 1;
  
  scp=$data/wav.scp
  
  required="$scp $mfcc_config"
  
  for f in $required; do
    if [ ! -f $f ]; then
      echo "make_mfcc.sh: no such file $f"
      exit 1;
    fi
  done
  
  # note: in general, the double-parenthesis construct in bash "((" is "C-style
  # syntax" where we can get rid of the $ for variable names, and omit spaces.
  # The "for" loop in this style is a special construct.
  
  
  if [ -f $data/segments ]; then
    echo "$0 [info]: segments file exists: using that."
    split_segments=""
    for ((n=1; n<=nj; n++)); do
      split_segments="$split_segments $logdir/segments.$n"
    done
  
    utils/split_scp.pl $data/segments $split_segments || exit 1;
    rm $logdir/.error 2>/dev/null
  
    $cmd JOB=1:$nj $logdir/make_mfcc.JOB.log \
      extract-segments scp:$scp $logdir/segments.JOB ark:- \| \
      compute-mfcc-feats --verbose=2 --config=$mfcc_config ark:- \
      ark,scp:$mfccdir/raw_mfcc_$name.JOB.ark,$mfccdir/raw_mfcc_$name.JOB.scp \
       || exit 1;
  
  else
    echo "$0: [info]: no segments file exists: assuming wav.scp indexed by utterance."
    split_scps=""
    for ((n=1; n<=nj; n++)); do
      split_scps="$split_scps $logdir/wav.$n.scp"
    done
  
    utils/split_scp.pl $scp $split_scps || exit 1;
   
    $cmd JOB=1:$nj $logdir/make_mfcc.JOB.log \
      compute-mfcc-feats  --verbose=2 --config=$mfcc_config scp:$logdir/wav.JOB.scp \
        ark,scp:$mfccdir/raw_mfcc_$name.JOB.ark,$mfccdir/raw_mfcc_$name.JOB.scp \
        || exit 1;
  
  fi
  
  
  if [ -f $logdir/.error.$name ]; then
    echo "Error producing mfcc features for $name:"
    tail $logdir/make_mfcc.*.log
    exit 1;
  fi
  
  # concatenate the .scp files together.
  for ((n=1; n<=nj; n++)); do
    cat $mfccdir/raw_mfcc_$name.$n.scp || exit 1;
  done > $data/feats.scp
  
  rm $logdir/wav.*.scp  $logdir/segments.* 2>/dev/null
  
  nf=`cat $data/feats.scp | wc -l` 
  nu=`cat $data/utt2spk | wc -l` 
  if [ $nf -ne $nu ]; then
    echo "It seems not all of the feature files were successfully processed ($nf != $nu);"
    echo "consider using utils/fix_data_dir.sh $data"
  fi
  
  echo "Succeeded creating MFCC features for $name"