OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
3 # | 3 # |
4 # Use of this source code is governed by a BSD-style license | 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 | 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 | 6 # tree. An additional intellectual property rights grant can be found |
7 # in the file PATENTS. All contributing project authors may | 7 # in the file PATENTS. All contributing project authors may |
8 # be found in the AUTHORS file in the root of the source tree. | 8 # be found in the AUTHORS file in the root of the source tree. |
9 | 9 |
10 """Perform APM module quality assessment on one or more input files using one or | 10 """Perform APM module quality assessment on one or more input files using one or |
11 more audioproc_f configuration files and one or more test data generators. | 11 more audioproc_f configuration files and one or more test data generators. |
12 | 12 |
13 Usage: apm_quality_assessment.py -i audio1.wav [audio2.wav ...] | 13 Usage: apm_quality_assessment.py -i audio1.wav [audio2.wav ...] |
14 -c cfg1.json [cfg2.json ...] | 14 -c cfg1.json [cfg2.json ...] |
15 -n white [echo ...] | 15 -n white [echo ...] |
16 -e audio_level [polqa ...] | 16 -e audio_level [polqa ...] |
17 -o /path/to/output | 17 -o /path/to/output |
18 """ | 18 """ |
19 | 19 |
20 import argparse | 20 import argparse |
21 import logging | 21 import logging |
22 import os | 22 import os |
23 import sys | 23 import sys |
24 | 24 |
25 import quality_assessment.audioproc_wrapper as audioproc_wrapper | 25 import quality_assessment.audioproc_wrapper as audioproc_wrapper |
26 import quality_assessment.echo_path_simulation as echo_path_simulation | |
26 import quality_assessment.eval_scores as eval_scores | 27 import quality_assessment.eval_scores as eval_scores |
27 import quality_assessment.evaluation as evaluation | 28 import quality_assessment.evaluation as evaluation |
28 import quality_assessment.test_data_generation as test_data_generation | 29 import quality_assessment.test_data_generation as test_data_generation |
29 import quality_assessment.simulation as simulation | 30 import quality_assessment.simulation as simulation |
30 | 31 |
32 _ECHO_PATH_SIMULATOR_NAMES = ( | |
33 echo_path_simulation.EchoPathSimulator.REGISTERED_CLASSES) | |
31 _TEST_DATA_GENERATOR_CLASSES = ( | 34 _TEST_DATA_GENERATOR_CLASSES = ( |
32 test_data_generation.TestDataGenerator.REGISTERED_CLASSES) | 35 test_data_generation.TestDataGenerator.REGISTERED_CLASSES) |
33 _TEST_DATA_GENERATORS_NAMES = _TEST_DATA_GENERATOR_CLASSES.keys() | 36 _TEST_DATA_GENERATORS_NAMES = _TEST_DATA_GENERATOR_CLASSES.keys() |
34 _EVAL_SCORE_WORKER_CLASSES = eval_scores.EvaluationScore.REGISTERED_CLASSES | 37 _EVAL_SCORE_WORKER_CLASSES = eval_scores.EvaluationScore.REGISTERED_CLASSES |
35 _EVAL_SCORE_WORKER_NAMES = _EVAL_SCORE_WORKER_CLASSES.keys() | 38 _EVAL_SCORE_WORKER_NAMES = _EVAL_SCORE_WORKER_CLASSES.keys() |
36 | 39 |
37 _DEFAULT_CONFIG_FILE = 'apm_configs/default.json' | 40 _DEFAULT_CONFIG_FILE = 'apm_configs/default.json' |
38 | 41 |
39 _POLQA_BIN_NAME = 'PolqaOem64' | 42 _POLQA_BIN_NAME = 'PolqaOem64' |
40 | 43 |
41 | 44 |
42 def _InstanceArgumentsParser(): | 45 def _InstanceArgumentsParser(): |
43 """Arguments parser factory. | 46 """Arguments parser factory. |
44 """ | 47 """ |
45 parser = argparse.ArgumentParser(description=( | 48 parser = argparse.ArgumentParser(description=( |
46 'Perform APM module quality assessment on one or more input files using ' | 49 'Perform APM module quality assessment on one or more input files using ' |
47 'one or more audioproc_f configuration files and one or more ' | 50 'one or more audioproc_f configuration files and one or more ' |
48 'test data generators.')) | 51 'test data generators.')) |
49 | 52 |
50 parser.add_argument('-c', '--config_files', nargs='+', required=False, | 53 parser.add_argument('-c', '--config_files', nargs='+', required=False, |
51 help=('path to the configuration files defining the ' | 54 help=('path to the configuration files defining the ' |
52 'arguments with which the audioproc_f tool is ' | 55 'arguments with which the audioproc_f tool is ' |
53 'called'), | 56 'called'), |
54 default=[_DEFAULT_CONFIG_FILE]) | 57 default=[_DEFAULT_CONFIG_FILE]) |
55 | 58 |
56 parser.add_argument('-i', '--input_files', nargs='+', required=True, | 59 parser.add_argument('-i', '--capture_input_files', nargs='+', required=True, |
57 help='path to the input wav files (one or more)') | 60 help='path to the capture input wav files (one or more)') |
61 | |
62 parser.add_argument('-r', '--render_input_files', nargs='+', required=False, | |
63 help=('path to the render input wav files; either ' | |
64 'omitted or one file for each file in ' | |
65 '--capture_input_files (files will be paired by ' | |
66 'index)'), default=None) | |
67 | |
68 parser.add_argument('-p', '--echo_path_simulator', required=False, | |
69 help=('custom echo path simulator name; required if ' | |
70 '--render_input_files is specified'), | |
71 choices=_ECHO_PATH_SIMULATOR_NAMES, default=None) | |
58 | 72 |
59 parser.add_argument('-t', '--test_data_generators', nargs='+', required=False, | 73 parser.add_argument('-t', '--test_data_generators', nargs='+', required=False, |
60 help='custom list of test data generators to use', | 74 help='custom list of test data generators to use', |
61 choices=_TEST_DATA_GENERATORS_NAMES, | 75 choices=_TEST_DATA_GENERATORS_NAMES, |
62 default=_TEST_DATA_GENERATORS_NAMES) | 76 default=_TEST_DATA_GENERATORS_NAMES) |
63 | 77 |
64 parser.add_argument('-e', '--eval_scores', nargs='+', required=False, | 78 parser.add_argument('-e', '--eval_scores', nargs='+', required=False, |
65 help='custom list of evaluation scores to use', | 79 help='custom list of evaluation scores to use', |
66 choices=_EVAL_SCORE_WORKER_NAMES, | 80 choices=_EVAL_SCORE_WORKER_NAMES, |
67 default=_EVAL_SCORE_WORKER_NAMES) | 81 default=_EVAL_SCORE_WORKER_NAMES) |
(...skipping 12 matching lines...) Expand all Loading... | |
80 | 94 |
81 return parser | 95 return parser |
82 | 96 |
83 | 97 |
84 def main(): | 98 def main(): |
85 # TODO(alessiob): level = logging.INFO once debugged. | 99 # TODO(alessiob): level = logging.INFO once debugged. |
86 logging.basicConfig(level=logging.DEBUG) | 100 logging.basicConfig(level=logging.DEBUG) |
87 | 101 |
88 parser = _InstanceArgumentsParser() | 102 parser = _InstanceArgumentsParser() |
89 args = parser.parse_args() | 103 args = parser.parse_args() |
104 if args.capture_input_files and args.render_input_files and ( | |
105 len(args.capture_input_files) != len(args.render_input_files)): | |
106 parser.error('when --render_input_files is set, it has to have the same ' | |
107 'length of --capture_input_files') | |
peah-webrtc
2017/05/03 08:10:08
"of" seems wrong in this sentence, please reformul
AleBzk
2017/05/15 08:22:57
Done.
| |
108 sys.exit(1) | |
109 if args.render_input_files and not args.echo_path_simulator: | |
110 parser.error('when --render_input_files is set, --echo_path_simulator is ' | |
111 'also required') | |
112 sys.exit(1) | |
90 | 113 |
91 simulator = simulation.ApmModuleSimulator( | 114 simulator = simulation.ApmModuleSimulator( |
92 aechen_ir_database_path=args.air_db_path, | 115 aechen_ir_database_path=args.air_db_path, |
93 polqa_tool_bin_path=os.path.join(args.polqa_path, _POLQA_BIN_NAME), | 116 polqa_tool_bin_path=os.path.join(args.polqa_path, _POLQA_BIN_NAME), |
94 ap_wrapper=audioproc_wrapper.AudioProcWrapper(), | 117 ap_wrapper=audioproc_wrapper.AudioProcWrapper(), |
95 evaluator=evaluation.ApmModuleEvaluator()) | 118 evaluator=evaluation.ApmModuleEvaluator()) |
96 simulator.Run( | 119 simulator.Run( |
97 config_filepaths=args.config_files, | 120 config_filepaths=args.config_files, |
98 input_filepaths=args.input_files, | 121 capture_input_filepaths=args.capture_input_files, |
122 render_input_filepaths=args.render_input_files, | |
123 echo_path_simulator_name=args.echo_path_simulator, | |
99 test_data_generator_names=args.test_data_generators, | 124 test_data_generator_names=args.test_data_generators, |
100 eval_score_names=args.eval_scores, | 125 eval_score_names=args.eval_scores, |
101 output_dir=args.output_dir) | 126 output_dir=args.output_dir) |
102 | 127 |
103 sys.exit(0) | 128 sys.exit(0) |
104 | 129 |
105 | 130 |
106 if __name__ == '__main__': | 131 if __name__ == '__main__': |
107 main() | 132 main() |
OLD | NEW |