generator.cc (3236B)
1 /* 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include <cstdio> 12 #include <iostream> 13 #include <memory> 14 #include <string> 15 #include <utility> 16 #include <vector> 17 18 #include "absl/flags/flag.h" 19 #include "absl/flags/parse.h" 20 #include "modules/audio_processing/test/conversational_speech/config.h" 21 #include "modules/audio_processing/test/conversational_speech/multiend_call.h" 22 #include "modules/audio_processing/test/conversational_speech/simulator.h" 23 #include "modules/audio_processing/test/conversational_speech/timing.h" 24 #include "modules/audio_processing/test/conversational_speech/wavreader_factory.h" 25 #include "rtc_base/checks.h" 26 #include "test/testsupport/file_utils.h" 27 28 ABSL_FLAG(std::string, i, "", "Directory containing the speech turn wav files"); 29 ABSL_FLAG(std::string, t, "", "Path to the timing text file"); 30 ABSL_FLAG(std::string, o, "", "Output wav files destination path"); 31 32 namespace webrtc { 33 namespace test { 34 namespace { 35 36 const char kUsageDescription[] = 37 "Usage: conversational_speech_generator\n" 38 " -i <path/to/source/audiotracks>\n" 39 " -t <path/to/timing_file.txt>\n" 40 " -o <output/path>\n" 41 "\n\n" 42 "Command-line tool to generate multiple-end audio tracks to simulate " 43 "conversational speech with two or more participants.\n"; 44 45 } // namespace 46 47 int main(int argc, char* argv[]) { 48 std::vector<char*> args = absl::ParseCommandLine(argc, argv); 49 if (args.size() != 1) { 50 printf("%s", kUsageDescription); 51 return 1; 52 } 53 RTC_CHECK(DirExists(absl::GetFlag(FLAGS_i))); 54 RTC_CHECK(FileExists(absl::GetFlag(FLAGS_t))); 55 RTC_CHECK(DirExists(absl::GetFlag(FLAGS_o))); 56 57 conversational_speech::Config config( 58 absl::GetFlag(FLAGS_i), absl::GetFlag(FLAGS_t), absl::GetFlag(FLAGS_o)); 59 60 // Load timing. 61 std::vector<conversational_speech::Turn> timing = 62 conversational_speech::LoadTiming(config.timing_filepath()); 63 64 // Parse timing and audio tracks. 65 auto wavreader_factory = 66 std::make_unique<conversational_speech::WavReaderFactory>(); 67 conversational_speech::MultiEndCall multiend_call( 68 timing, config.audiotracks_path(), std::move(wavreader_factory)); 69 70 // Generate output audio tracks. 71 auto generated_audiotrack_pairs = 72 conversational_speech::Simulate(multiend_call, config.output_path()); 73 74 // Show paths to created audio tracks. 75 std::cout << "Output files:" << std::endl; 76 for (const auto& output_paths_entry : *generated_audiotrack_pairs) { 77 std::cout << " speaker: " << output_paths_entry.first << std::endl; 78 std::cout << " near end: " << output_paths_entry.second.near_end 79 << std::endl; 80 std::cout << " far end: " << output_paths_entry.second.far_end 81 << std::endl; 82 } 83 84 return 0; 85 } 86 87 } // namespace test 88 } // namespace webrtc 89 90 int main(int argc, char* argv[]) { 91 return webrtc::test::main(argc, argv); 92 }