diff --git a/modules/audio_processing/agc2/rnn_vad/BUILD.gn b/modules/audio_processing/agc2/rnn_vad/BUILD.gn index ff4be5cb89..670bbb6c13 100644 --- a/modules/audio_processing/agc2/rnn_vad/BUILD.gn +++ b/modules/audio_processing/agc2/rnn_vad/BUILD.gn @@ -125,6 +125,8 @@ if (rtc_include_tests) { "../../../../common_audio", "../../../../rtc_base:rtc_base_approved", "../../../../test:test_support", + "//third_party/abseil-cpp/absl/flags:flag", + "//third_party/abseil-cpp/absl/flags:parse", ] } } diff --git a/modules/audio_processing/agc2/rnn_vad/rnn_vad_tool.cc b/modules/audio_processing/agc2/rnn_vad/rnn_vad_tool.cc index 8d61bd8d4b..c5293bedc7 100644 --- a/modules/audio_processing/agc2/rnn_vad/rnn_vad_tool.cc +++ b/modules/audio_processing/agc2/rnn_vad/rnn_vad_tool.cc @@ -12,48 +12,30 @@ #include #include +#include "absl/flags/flag.h" +#include "absl/flags/parse.h" #include "common_audio/resampler/push_sinc_resampler.h" #include "common_audio/wav_file.h" #include "modules/audio_processing/agc2/rnn_vad/common.h" #include "modules/audio_processing/agc2/rnn_vad/features_extraction.h" #include "modules/audio_processing/agc2/rnn_vad/rnn.h" -#include "rtc_base/flags.h" #include "rtc_base/logging.h" +ABSL_FLAG(std::string, i, "", "Path to the input wav file"); +ABSL_FLAG(std::string, f, "", "Path to the output features file"); +ABSL_FLAG(std::string, o, "", "Path to the output VAD probabilities file"); + namespace webrtc { namespace rnn_vad { namespace test { -namespace { - -WEBRTC_DEFINE_string(i, "", "Path to the input wav file"); -std::string InputWavFile() { - return static_cast(FLAG_i); -} - -WEBRTC_DEFINE_string(f, "", "Path to the output features file"); -std::string OutputFeaturesFile() { - return static_cast(FLAG_f); -} - -WEBRTC_DEFINE_string(o, "", "Path to the output VAD probabilities file"); -std::string OutputVadProbsFile() { - return static_cast(FLAG_o); -} - -WEBRTC_DEFINE_bool(help, false, "Prints this message"); - -} // namespace int main(int argc, char* argv[]) { + absl::ParseCommandLine(argc, argv); rtc::LogMessage::LogToDebug(rtc::LS_INFO); - rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true); - if (FLAG_help) { - rtc::FlagList::Print(nullptr, false); - return 0; - } // Open wav input file and check properties. - WavReader wav_reader(InputWavFile()); + const std::string input_wav_file = absl::GetFlag(FLAGS_i); + WavReader wav_reader(input_wav_file); if (wav_reader.num_channels() != 1) { RTC_LOG(LS_ERROR) << "Only mono wav files are supported"; return 1; @@ -65,9 +47,10 @@ int main(int argc, char* argv[]) { RTC_LOG(LS_INFO) << "Input sample rate: " << wav_reader.sample_rate(); // Init output files. - FILE* vad_probs_file = fopen(OutputVadProbsFile().c_str(), "wb"); + const std::string output_vad_probs_file = absl::GetFlag(FLAGS_o); + FILE* vad_probs_file = fopen(output_vad_probs_file.c_str(), "wb"); FILE* features_file = nullptr; - const std::string output_feature_file = OutputFeaturesFile(); + const std::string output_feature_file = absl::GetFlag(FLAGS_f); if (!output_feature_file.empty()) { features_file = fopen(output_feature_file.c_str(), "wb"); } @@ -119,10 +102,10 @@ int main(int argc, char* argv[]) { // Close output file(s). fclose(vad_probs_file); - RTC_LOG(LS_INFO) << "VAD probabilities written to " << FLAG_o; + RTC_LOG(LS_INFO) << "VAD probabilities written to " << output_vad_probs_file; if (features_file) { fclose(features_file); - RTC_LOG(LS_INFO) << "features written to " << FLAG_f; + RTC_LOG(LS_INFO) << "features written to " << output_feature_file; } return 0;