27 int main(
int argc,
char *argv[]) {
29 using namespace kaldi;
33 "This program reads input features and writes out, for each utterance,\n" 34 "a vector of floats that are 1.0 if we judge the frame voiced and 0.0\n" 35 "otherwise. The algorithm is very simple and is based on thresholding\n" 36 "the log mel energy (and taking the consensus of threshold decisions\n" 37 "within a window centered on the current frame). See the options for\n" 38 "more details, and egs/sid/s1/run.sh for examples; this program is\n" 39 "intended for use in speaker-ID.\n" 41 "Usage: compute-vad [options] <feats-rspecifier> <vad-wspecifier>\n" 42 "e.g.: compute-vad scp:feats.scp ark:vad.ark\n";
45 bool omit_unvoiced_utts =
false;
46 po.
Register(
"omit-unvoiced-utts", &omit_unvoiced_utts,
47 "If true, do not write out voicing information for " 48 "utterances that were judged 100% unvoiced.");
58 std::string feat_rspecifier = po.
GetArg(1);
59 std::string vad_wspecifier = po.
GetArg(2);
64 int32 num_done = 0, num_err = 0;
65 int32 num_unvoiced = 0;
66 double tot_length = 0.0, tot_decision = 0.0;
68 for (;!feat_reader.
Done(); feat_reader.
Next()) {
69 std::string utt = feat_reader.
Key();
71 if (feat.NumRows() == 0) {
72 KALDI_WARN <<
"Empty feature matrix for utterance " << utt;
80 double sum = vad_result.Sum();
82 KALDI_WARN <<
"No frames were judged voiced for utterance " << utt;
87 tot_decision += vad_result.Sum();
88 tot_length += vad_result.Dim();
90 if (!(omit_unvoiced_utts && sum == 0)) {
91 vad_writer.
Write(utt, vad_result);
95 KALDI_LOG <<
"Applied energy based voice activity detection; " 96 <<
"processed " << num_done <<
" utterances successfully; " 97 << num_err <<
" had empty features, and " << num_unvoiced
98 <<
" were completely unvoiced.";
99 KALDI_LOG <<
"Proportion of voiced frames was " 100 << (tot_decision / tot_length) <<
" over " 101 << tot_length <<
" frames.";
102 return (num_done != 0 ? 0 : 1);
103 }
catch(
const std::exception &e) {
104 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
A templated class for writing objects to an archive or script file; see The Table concept...
int main(int argc, char *argv[])
void Write(const std::string &key, const T &value) const
void Register(const std::string &name, bool *ptr, const std::string &doc)
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
void Register(OptionsItf *opts)
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
A class representing a vector.
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.