27 int main(
int argc,
char *argv[]) {
29 using namespace kaldi;
33 "Scale posteriors with either a global scale, or a different scale for " 35 "Usage: scale-post <post-rspecifier> (<scale-rspecifier>|<scale>) <post-wspecifier>\n";
45 std::string post_rspecifier = po.
GetArg(1),
46 scale_or_scale_rspecifier = po.
GetArg(2),
47 post_wspecifier = po.
GetArg(3);
49 double global_scale = 0.0;
53 KALDI_ERR <<
"Bad second argument " << scale_or_scale_rspecifier
54 <<
" (expected scale or scale rspecifier)";
55 scale_or_scale_rspecifier =
"";
63 int32 num_scaled = 0, num_no_scale = 0;
65 for (; !posterior_reader.
Done(); posterior_reader.
Next()) {
66 std::string key = posterior_reader.
Key();
69 if (scale_or_scale_rspecifier !=
"" && !scale_reader.
HasKey(key)) {
72 BaseFloat post_scale = (scale_or_scale_rspecifier ==
"" ? global_scale
73 : scale_reader.
Value(key));
76 posterior_writer.
Write(key, posterior);
79 KALDI_LOG <<
"Done " << num_scaled <<
" posteriors; " << num_no_scale
81 return (num_scaled != 0 ? 0 : 1);
82 }
catch(
const std::exception &e) {
83 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...
void Write(const std::string &key, const T &value) const
RspecifierType ClassifyRspecifier(const std::string &rspecifier, std::string *rxfilename, RspecifierOptions *opts)
Allows random access to a collection of objects in an archive or script file; see The Table concept...
std::vector< std::vector< std::pair< int32, BaseFloat > > > Posterior
Posterior is a typedef for storing acoustic-state (actually, transition-id) posteriors over an uttera...
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
const T & Value(const std::string &key)
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.
bool ConvertStringToReal(const std::string &str, T *out)
ConvertStringToReal converts a string into either float or double and returns false if there was any ...
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
bool HasKey(const std::string &key)
void ScalePosterior(BaseFloat scale, Posterior *post)
Scales the BaseFloat (weight) element in the posterior entries.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
int main(int argc, char *argv[])