The class ParseOptions handles the parsing of command-line options given to main() via argc and argv. First we give an example of how we invoke a typical Kaldi program from the command-line:
gmm-align --transition-scale=10.0 --beam=75 \ exp/mono/tree exp/mono/30.mdl data/L.fst \ 'ark:add-deltas --print-args=false scp:data/train.scp ark:- |' \ ark:data/train.tra ark:exp/tri/0.ali
The command-line options, which only have a long form (there are no one-letter options), must appear before the positional arguments. In this case there are six positional arguments, starting from
"exp/mono/tree"; notice that the one starting with
"ark:add-deltas" is a single string with spaces in it; the single-quotes get interpreted by the shell; this argument gets invoked as a pipe.
We will illustrate how these options get handled at the C++ level by introducing some of the code from gmm-align.cc (we have modified it slightly to make it clearer):
The code above is mostly self-explanatory. In a normal Kaldi program, the sequence is as follows:
po.NumArgs()is in the valid range for your program.
po.GetArg(1)and so on; for optional positional arguments that may be out of range, the convenience function
po.GetOptArg(n)returns the n'th argument, or the empty string if n was out of range.
Typically when writing a new command-line Kaldi program, it will be easiest to copy an existing one and modify it.
Certain command-line options are automatically registered by the ParseOptions object itself. These include the following:
–configThis option loads command-line options from a config file. E.g. if we do –config=configs/my.conf, the file
--first-option=15 # This is the first option --second-option=false # This is the second option
–print-argsThis boolean option controls whether the program prints the command-line arguments to the standard error (default is true);
–print-args=falsewill turn this off.
–helpThis boolean argument, if true will cause the program to print out a usage message (like other boolean arguments, just
–helpcounts as true). You can usually get the usage message just by omitting all command-line arguments, because most programs require positional arguments.
–verboseThis controls the verbose level, so that messages logged with KALDI_VLOG will get printed out. More is higher (e.g. –verbose=2 is typical).