voice-activity-detection.cc
Go to the documentation of this file.
1 // ivector/voice-activity-detection.cc
2 
3 // Copyright 2013 Daniel Povey
4 
5 // See ../../COPYING for clarification regarding multiple authors
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 // MERCHANTABLITY OR NON-INFRINGEMENT.
17 // See the Apache 2 License for the specific language governing permissions and
18 // limitations under the License.
19 
20 
23 
24 
25 namespace kaldi {
26 
28  const MatrixBase<BaseFloat> &feats,
29  Vector<BaseFloat> *output_voiced) {
30  int32 T = feats.NumRows();
31  output_voiced->Resize(T);
32  if (T == 0) {
33  KALDI_WARN << "Empty features";
34  return;
35  }
36  Vector<BaseFloat> log_energy(T);
37  log_energy.CopyColFromMat(feats, 0); // column zero is log-energy.
38 
39  BaseFloat energy_threshold = opts.vad_energy_threshold;
40  if (opts.vad_energy_mean_scale != 0.0) {
42  energy_threshold += opts.vad_energy_mean_scale * log_energy.Sum() / T;
43  }
44 
47  opts.vad_proportion_threshold < 1.0);
48  for (int32 t = 0; t < T; t++) {
49  const BaseFloat *log_energy_data = log_energy.Data();
50  int32 num_count = 0, den_count = 0, context = opts.vad_frames_context;
51  for (int32 t2 = t - context; t2 <= t + context; t2++) {
52  if (t2 >= 0 && t2 < T) {
53  den_count++;
54  if (log_energy_data[t2] > energy_threshold)
55  num_count++;
56  }
57  }
58  if (num_count >= den_count * opts.vad_proportion_threshold)
59  (*output_voiced)(t) = 1.0;
60  else
61  (*output_voiced)(t) = 0.0;
62  }
63 }
64 
65 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
Base class which provides matrix operations not involving resizing or allocation. ...
Definition: kaldi-matrix.h:49
kaldi::int32 int32
void Resize(MatrixIndexT length, MatrixResizeType resize_type=kSetZero)
Set vector to a specified size (can be zero).
float BaseFloat
Definition: kaldi-types.h:29
#define KALDI_WARN
Definition: kaldi-error.h:150
Real * Data()
Returns a pointer to the start of the vector&#39;s data.
Definition: kaldi-vector.h:70
Real Sum() const
Returns sum of the elements.
void CopyColFromMat(const MatrixBase< OtherReal > &M, MatrixIndexT col)
Extracts a column of the matrix M.
A class representing a vector.
Definition: kaldi-vector.h:406
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
void ComputeVadEnergy(const VadEnergyOptions &opts, const MatrixBase< BaseFloat > &feats, Vector< BaseFloat > *output_voiced)
Compute voice-activity vector for a file: 1 if we judge the frame as voiced, 0 otherwise.