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 <iostream>
12 #include <vector>
13 
14 #include <memory>
15 
16 #include "absl/flags/flag.h"
17 #include "absl/flags/parse.h"
18 #include "modules/audio_processing/test/conversational_speech/config.h"
19 #include "modules/audio_processing/test/conversational_speech/multiend_call.h"
20 #include "modules/audio_processing/test/conversational_speech/simulator.h"
21 #include "modules/audio_processing/test/conversational_speech/timing.h"
22 #include "modules/audio_processing/test/conversational_speech/wavreader_factory.h"
23 #include "test/testsupport/file_utils.h"
24 
25 ABSL_FLAG(std::string, i, "", "Directory containing the speech turn wav files");
26 ABSL_FLAG(std::string, t, "", "Path to the timing text file");
27 ABSL_FLAG(std::string, o, "", "Output wav files destination path");
28 
29 namespace webrtc {
30 namespace test {
31 namespace {
32 
33 const char kUsageDescription[] =
34     "Usage: conversational_speech_generator\n"
35     "          -i <path/to/source/audiotracks>\n"
36     "          -t <path/to/timing_file.txt>\n"
37     "          -o <output/path>\n"
38     "\n\n"
39     "Command-line tool to generate multiple-end audio tracks to simulate "
40     "conversational speech with two or more participants.\n";
41 
42 }  // namespace
43 
main(int argc,char * argv[])44 int main(int argc, char* argv[]) {
45   std::vector<char*> args = absl::ParseCommandLine(argc, argv);
46   if (args.size() != 1) {
47     printf("%s", kUsageDescription);
48     return 1;
49   }
50   RTC_CHECK(DirExists(absl::GetFlag(FLAGS_i)));
51   RTC_CHECK(FileExists(absl::GetFlag(FLAGS_t)));
52   RTC_CHECK(DirExists(absl::GetFlag(FLAGS_o)));
53 
54   conversational_speech::Config config(
55       absl::GetFlag(FLAGS_i), absl::GetFlag(FLAGS_t), absl::GetFlag(FLAGS_o));
56 
57   // Load timing.
58   std::vector<conversational_speech::Turn> timing =
59       conversational_speech::LoadTiming(config.timing_filepath());
60 
61   // Parse timing and audio tracks.
62   auto wavreader_factory =
63       std::make_unique<conversational_speech::WavReaderFactory>();
64   conversational_speech::MultiEndCall multiend_call(
65       timing, config.audiotracks_path(), std::move(wavreader_factory));
66 
67   // Generate output audio tracks.
68   auto generated_audiotrack_pairs =
69       conversational_speech::Simulate(multiend_call, config.output_path());
70 
71   // Show paths to created audio tracks.
72   std::cout << "Output files:" << std::endl;
73   for (const auto& output_paths_entry : *generated_audiotrack_pairs) {
74     std::cout << "  speaker: " << output_paths_entry.first << std::endl;
75     std::cout << "    near end: " << output_paths_entry.second.near_end
76               << std::endl;
77     std::cout << "    far end: " << output_paths_entry.second.far_end
78               << std::endl;
79   }
80 
81   return 0;
82 }
83 
84 }  // namespace test
85 }  // namespace webrtc
86 
main(int argc,char * argv[])87 int main(int argc, char* argv[]) {
88   return webrtc::test::main(argc, argv);
89 }
90