From 0cf3aa6d0d170365a2dedb57960fbface736f851 Mon Sep 17 00:00:00 2001 From: alessiob Date: Wed, 15 Mar 2017 07:56:26 -0700 Subject: [PATCH] C++ porting of the initial python script for conversational speech generation. This CL removes the Python script and adds its C++ porting. The former was in its early stage and it has permanently been removed. BUG=webrtc:7218 NOTRY=True Review-Url: https://codereview.webrtc.org/2740063004 Cr-Commit-Position: refs/heads/master@{#17254} --- webrtc/modules/audio_processing/BUILD.gn | 1 + .../test/conversational_speech/BUILD.gn | 31 +++++++++ .../OWNERS | 0 .../README.md | 8 +-- .../conversational_speech/convspeech_gen.cc | 68 +++++++++++++++++++ .../test/conversational_speech/settings.cc | 29 ++++++++ .../test/conversational_speech/settings.h | 39 +++++++++++ .../generate_conversational_tracks.py | 58 ---------------- .../test_generation.py | 20 ------ 9 files changed, 172 insertions(+), 82 deletions(-) create mode 100644 webrtc/modules/audio_processing/test/conversational_speech/BUILD.gn rename webrtc/modules/audio_processing/test/{py_conversational_speech => conversational_speech}/OWNERS (100%) rename webrtc/modules/audio_processing/test/{py_conversational_speech => conversational_speech}/README.md (92%) create mode 100644 webrtc/modules/audio_processing/test/conversational_speech/convspeech_gen.cc create mode 100644 webrtc/modules/audio_processing/test/conversational_speech/settings.cc create mode 100644 webrtc/modules/audio_processing/test/conversational_speech/settings.h delete mode 100644 webrtc/modules/audio_processing/test/py_conversational_speech/generate_conversational_tracks.py delete mode 100644 webrtc/modules/audio_processing/test/py_conversational_speech/test_generation.py diff --git a/webrtc/modules/audio_processing/BUILD.gn b/webrtc/modules/audio_processing/BUILD.gn index 84f25b5e8e..b20e3b5ad1 100644 --- a/webrtc/modules/audio_processing/BUILD.gn +++ b/webrtc/modules/audio_processing/BUILD.gn @@ -475,6 +475,7 @@ if (rtc_include_tests) { ":audioproc_f", ":audioproc_unittest_proto", ":unpack_aecdump", + "test/conversational_speech", "test/py_quality_assessment", ] } diff --git a/webrtc/modules/audio_processing/test/conversational_speech/BUILD.gn b/webrtc/modules/audio_processing/test/conversational_speech/BUILD.gn new file mode 100644 index 0000000000..09f8a2625e --- /dev/null +++ b/webrtc/modules/audio_processing/test/conversational_speech/BUILD.gn @@ -0,0 +1,31 @@ +# Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. +# +# Use of this source code is governed by a BSD-style license +# that can be found in the LICENSE file in the root of the source +# tree. An additional intellectual property rights grant can be found +# in the file PATENTS. All contributing project authors may +# be found in the AUTHORS file in the root of the source tree. + +import("../../../../webrtc.gni") + +group("conversational_speech") { + testonly = true + deps = [ + ":convspeech_gen", + ] +} + +rtc_executable("convspeech_gen") { + testonly = true + sources = [ + "convspeech_gen.cc", + "settings.cc", + "settings.h", + ] + deps = [ + "//third_party/gflags", + "//webrtc/base:rtc_base_approved", + "//webrtc/test:fileutils", + ] + visibility = [ ":*" ] # Only targets in this file can depend on this. +} diff --git a/webrtc/modules/audio_processing/test/py_conversational_speech/OWNERS b/webrtc/modules/audio_processing/test/conversational_speech/OWNERS similarity index 100% rename from webrtc/modules/audio_processing/test/py_conversational_speech/OWNERS rename to webrtc/modules/audio_processing/test/conversational_speech/OWNERS diff --git a/webrtc/modules/audio_processing/test/py_conversational_speech/README.md b/webrtc/modules/audio_processing/test/conversational_speech/README.md similarity index 92% rename from webrtc/modules/audio_processing/test/py_conversational_speech/README.md rename to webrtc/modules/audio_processing/test/conversational_speech/README.md index 79d07fdf08..415c65b027 100644 --- a/webrtc/modules/audio_processing/test/py_conversational_speech/README.md +++ b/webrtc/modules/audio_processing/test/conversational_speech/README.md @@ -1,7 +1,7 @@ -#Conversational Speech generator tool +# Conversational Speech generator tool -Python tool to generate multiple-end audio tracks to simulate conversational -speech with two or more participants. +Tool to generate multiple-end audio tracks to simulate conversational speech +with two or more participants. The input to the tool is a directory containing a number of audio tracks and a text file indicating how to time the sequence of speech turns (see the Example @@ -21,7 +21,7 @@ and silence in the conversation. IMPORTANT: **the whole code has not been landed yet.** -###Example +### Example For each end, there is a set of audio tracks, e.g., a1, a2 and a3 (speaker A) and b1, b2 (speaker B). diff --git a/webrtc/modules/audio_processing/test/conversational_speech/convspeech_gen.cc b/webrtc/modules/audio_processing/test/conversational_speech/convspeech_gen.cc new file mode 100644 index 0000000000..2b88597987 --- /dev/null +++ b/webrtc/modules/audio_processing/test/conversational_speech/convspeech_gen.cc @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include + +#include "gflags/gflags.h" +#include "webrtc/base/logging.h" +#include "webrtc/modules/audio_processing/test/conversational_speech/settings.h" +#include "webrtc/test/testsupport/fileutils.h" + +namespace webrtc { +namespace test { +namespace { + +// Adapting DirExists/FileExists interfaces to DEFINE_validator. +auto dir_exists = [](const char* c, const std::string& dirpath) { + return DirExists(dirpath); +}; +auto file_exists = [](const char* c, const std::string& filepath) { + return FileExists(filepath); +}; + +const char kUsageDescription[] = + "Usage: convspeech_gen\n" + " -i \n" + " -t \n" + " -o \n" + "\n\n" + "Command-line tool to generate multiple-end audio tracks to simulate " + "conversational speech with two or more participants."; + +DEFINE_string(i, "", "Directory containing the speech turn wav files"); +DEFINE_validator(i, dir_exists); +DEFINE_string(t, "", "Path to the timing text file"); +DEFINE_validator(t, file_exists); +DEFINE_string(o, "", "Output wav files destination path"); +DEFINE_validator(o, dir_exists); + +} // namespace + +int main(int argc, char* argv[]) { + google::SetUsageMessage(kUsageDescription); + google::ParseCommandLineFlags(&argc, &argv, true); + + ConvSpeechGeneratorSettings settings(FLAGS_i, FLAGS_t, FLAGS_o); + + // TODO(alessiob): remove line below once debugged. + rtc::LogMessage::LogToDebug(rtc::LS_VERBOSE); + LOG(LS_VERBOSE) << "i = " << settings.audiotracks_path(); + LOG(LS_VERBOSE) << "t = " << settings.timing_filepath(); + LOG(LS_VERBOSE) << "o = " << settings.output_path(); + + return 0; +} + +} // namespace test +} // namespace webrtc + +int main(int argc, char* argv[]) { + return webrtc::test::main(argc, argv); +} diff --git a/webrtc/modules/audio_processing/test/conversational_speech/settings.cc b/webrtc/modules/audio_processing/test/conversational_speech/settings.cc new file mode 100644 index 0000000000..8b2e88b493 --- /dev/null +++ b/webrtc/modules/audio_processing/test/conversational_speech/settings.cc @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "webrtc/modules/audio_processing/test/conversational_speech/settings.h" + +namespace webrtc { +namespace test { + +const std::string& ConvSpeechGeneratorSettings::audiotracks_path() const { + return audiotracks_path_; +} + +const std::string& ConvSpeechGeneratorSettings::timing_filepath() const { + return timing_filepath_; +} + +const std::string& ConvSpeechGeneratorSettings::output_path() const { + return output_path_; +} + +} // namespace test +} // namespace webrtc diff --git a/webrtc/modules/audio_processing/test/conversational_speech/settings.h b/webrtc/modules/audio_processing/test/conversational_speech/settings.h new file mode 100644 index 0000000000..ea360b7952 --- /dev/null +++ b/webrtc/modules/audio_processing/test/conversational_speech/settings.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_TEST_CONVERSATIONAL_SPEECH_SETTINGS_H_ +#define WEBRTC_MODULES_AUDIO_PROCESSING_TEST_CONVERSATIONAL_SPEECH_SETTINGS_H_ + +#include + +namespace webrtc { +namespace test { + +struct ConvSpeechGeneratorSettings { + ConvSpeechGeneratorSettings(const std::string& audiotracks_path, + const std::string& timing_filepath, + const std::string& output_path) + : audiotracks_path_(audiotracks_path), + timing_filepath_(timing_filepath), + output_path_(output_path) {} + + const std::string& audiotracks_path() const; + const std::string& timing_filepath() const; + const std::string& output_path() const; + + const std::string audiotracks_path_; + const std::string timing_filepath_; + const std::string output_path_; +}; + +} // namespace test +} // namespace webrtc + +#endif // WEBRTC_MODULES_AUDIO_PROCESSING_TEST_CONVERSATIONAL_SPEECH_SETTINGS_H_ diff --git a/webrtc/modules/audio_processing/test/py_conversational_speech/generate_conversational_tracks.py b/webrtc/modules/audio_processing/test/py_conversational_speech/generate_conversational_tracks.py deleted file mode 100644 index 41e3bbdc6b..0000000000 --- a/webrtc/modules/audio_processing/test/py_conversational_speech/generate_conversational_tracks.py +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env python -# Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. -# -# Use of this source code is governed by a BSD-style license -# that can be found in the LICENSE file in the root of the source -# tree. An additional intellectual property rights grant can be found -# in the file PATENTS. All contributing project authors may -# be found in the AUTHORS file in the root of the source tree. - -"""Generate multiple-end audio tracks to simulate conversational - speech with two or more participants. - -Usage: generate_conversational_tracks.py - -i path/to/source/audiotracks - -t path/to/timing_file.txt - -o output/path -""" - -import argparse -import logging -import sys - -def _InstanceArgumentsParser(): - parser = argparse.ArgumentParser(description=( - 'Generate multiple-end audio tracks to simulate conversational speech ' - 'with two or more participants.')) - - parser.add_argument('-i', '--input_tracks_path', required=True, - help='directory containing the speech turn wav files') - - parser.add_argument('-t', '--timing_file', required=True, - help='path to the timing text file') - - parser.add_argument('-o', '--output_dir', required=False, - help=('base path to the output directory in which the ' - 'output wav files are saved'), - default='output') - - return parser - - -def main(): - # TODO(alessiob): level = logging.INFO once debugged. - logging.basicConfig(level=logging.DEBUG) - - parser = _InstanceArgumentsParser() - args = parser.parse_args() - - # TODO(alessiob): pass the arguments to the app controller. - - # TODO(alessiob): remove when comment above addressed. - logging.debug(args) - - sys.exit(0) - - -if __name__ == '__main__': - main() diff --git a/webrtc/modules/audio_processing/test/py_conversational_speech/test_generation.py b/webrtc/modules/audio_processing/test/py_conversational_speech/test_generation.py deleted file mode 100644 index 3fc34e399d..0000000000 --- a/webrtc/modules/audio_processing/test/py_conversational_speech/test_generation.py +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env python -# Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. -# -# Use of this source code is governed by a BSD-style license -# that can be found in the LICENSE file in the root of the source -# tree. An additional intellectual property rights grant can be found -# in the file PATENTS. All contributing project authors may -# be found in the AUTHORS file in the root of the source tree. - -import unittest - -import generate_conversational_tracks - -class TestGenerationScript(unittest.TestCase): - - def TestMain(self): - # Exit with error code if no arguments are passed. - with self.assertRaises(SystemExit) as cm: - generate_conversational_tracks.main() - self.assertGreater(cm.exception.code, 0)