text
stringlengths
0
2.2M
#include <vector>
#include <gflags/gflags.h>
#include <glog/logging.h>
#include "flashlight/pkg/speech/common/Defines.h"
#include "flashlight/pkg/speech/criterion/criterion.h"
#include "flashlight/pkg/speech/data/FeatureTransforms.h"
#include "flashlight/pkg/speech/data/Utils.h"
#include "flashlight/pkg/speech/decoder/TranscriptionUtils.h"
#include "flashlight/pkg/speech/runtime/runtime.h"
#include "flashlight/pkg/runtime/common/SequentialBuilder.h"
#include "flashlight/pkg/runtime/common/Serializer.h"
#include "flashlight/lib/common/System.h"
#include "flashlight/lib/text/decoder/lm/KenLM.h"
#include "flashlight/lib/text/dictionary/Dictionary.h"
namespace {
DEFINE_double(
vad_threshold,
0.99,
"Blank probability threshold at which a frame is deemed voice-inactive");
DEFINE_string(outpath, "", "Output path for generated results files");
// Extensions for each output file
const std::string kVadExt = ".vad";
const std::string kTknFrameWiseTokensExt = ".fwt";
const std::string kLtrTranscriptExt = ".tsc";
const std::string kPerplexityPctSpeechExt = ".sts";
} // namespace
using namespace fl::pkg::speech;
using namespace fl::lib;
using namespace fl::pkg::runtime;
int main(int argc, char** argv) {
google::InitGoogleLogging(argv[0]);
google::InstallFailureSignalHandler();
std::string exec(argv[0]);
std::vector<std::string> argvs;
for (int i = 0; i < argc; i++) {
argvs.emplace_back(argv[i]);
}
gflags::SetUsageMessage("Usage: Please refer to https://git.io/JLbJ6");
if (argc <= 1) {
LOG(FATAL) << gflags::ProgramUsage();
}
fl::init();
/* ===================== Parse Options ===================== */
LOG(INFO) << "Parsing command line flags";
gflags::ParseCommandLineFlags(&argc, &argv, false);
auto flagsfile = FLAGS_flagsfile;
if (!flagsfile.empty()) {
LOG(INFO) << "Reading flags from file " << flagsfile;
gflags::ReadFromFlagsFile(flagsfile, argv[0], true);
}
/* ===================== Create Network ===================== */
std::shared_ptr<fl::Module> network;
std::shared_ptr<SequenceCriterion> criterion;
std::unordered_map<std::string, std::string> cfg;
std::string version;
LOG(INFO) << "[Network] Reading acoustic model from " << FLAGS_am;
fl::pkg::runtime::Serializer::load(FLAGS_am, version, cfg, network, criterion);
if (version != FL_APP_ASR_VERSION) {
LOG(WARNING) << "[Network] Model version " << version
<< " and code version " << FL_APP_ASR_VERSION;
}
network->eval();
criterion->eval();
LOG(INFO) << "[Network] " << network->prettyString();
LOG(INFO) << "[Criterion] " << criterion->prettyString();
LOG(INFO) << "[Network] Number of params: " << numTotalParams(network);
auto flags = cfg.find(kGflags);
if (flags == cfg.end()) {
LOG(FATAL) << "[Network] Invalid config loaded from " << FLAGS_am;
}
LOG(INFO) << "[Network] Updating flags from config file: " << FLAGS_am;
gflags::ReadFlagsFromString(flags->second, gflags::GetArgv0(), true);
// override with user-specified flags
gflags::ParseCommandLineFlags(&argc, &argv, false);
if (!flagsfile.empty()) {
gflags::ReadFromFlagsFile(flagsfile, argv[0], true);
}
LOG(INFO) << "Gflags after parsing \n" << serializeGflags("; ");
/* ===================== Create Dictionary ===================== */
fl::lib::text::Dictionary tokenDict(FLAGS_tokens);
// Setup-specific modifications
for (int64_t r = 1; r <= FLAGS_replabel; ++r) {
tokenDict.addEntry("<" + std::to_string(r) + ">");
}