OLD | NEW |
1 #!/usr/bin/env python3 | 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 |
| 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 noise generators. |
| 12 |
| 13 Usage: apm_quality_assessment.py -i audio1.wav [audio2.wav ...] |
| 14 -c cfg1.json [cfg2.json ...] |
| 15 -n white [echo ...] |
| 16 -e audio_level [polqa ...] |
| 17 -o /path/to/output |
| 18 """ |
| 19 |
| 20 import argparse |
| 21 import logging |
| 22 import sys |
| 23 |
| 24 import quality_assessment.eval_scores as eval_scores |
| 25 import quality_assessment.noise_generation as noise_generation |
| 26 import quality_assessment.simulation as simulation |
| 27 |
| 28 _NOISE_GENERATOR_CLASSES = noise_generation.NoiseGenerator.REGISTERED_CLASSES |
| 29 _NOISE_GENERATORS_NAMES = _NOISE_GENERATOR_CLASSES.keys() |
| 30 _EVAL_SCORE_WORKER_CLASSES = eval_scores.EvaluationScore.REGISTERED_CLASSES |
| 31 _EVAL_SCORE_WORKER_NAMES = _EVAL_SCORE_WORKER_CLASSES.keys() |
| 32 |
| 33 _DEFAULT_CONFIG_FILE = 'apm_configs/default.json' |
| 34 |
| 35 def _instance_arguments_parser(): |
| 36 parser = argparse.ArgumentParser(description=( |
| 37 'Perform APM module quality assessment on one or more input files using ' |
| 38 'one or more audioproc_f configuration files and one or more noise ' |
| 39 'generators.')) |
| 40 |
| 41 parser.add_argument('-c', '--config_files', nargs='+', required=False, |
| 42 help=('path to the configuration files defining the ' |
| 43 'arguments with which the audioproc_f tool is ' |
| 44 'called'), |
| 45 default=[_DEFAULT_CONFIG_FILE]) |
| 46 |
| 47 parser.add_argument('-i', '--input_files', nargs='+', required=True, |
| 48 help='path to the input wav files (one or more)') |
| 49 |
| 50 parser.add_argument('-n', '--noise_generators', nargs='+', required=False, |
| 51 help='custom list of noise generators to use', |
| 52 choices=_NOISE_GENERATORS_NAMES, |
| 53 default=_NOISE_GENERATORS_NAMES) |
| 54 |
| 55 parser.add_argument('-e', '--eval_scores', nargs='+', required=False, |
| 56 help='custom list of evaluation scores to use', |
| 57 choices=_EVAL_SCORE_WORKER_NAMES, |
| 58 default=_EVAL_SCORE_WORKER_NAMES) |
| 59 |
| 60 parser.add_argument('-o', '--output_dir', required=False, |
| 61 help=('base path to the output directory in which the ' |
| 62 'output wav files and the evaluation outcomes ' |
| 63 'are saved'), |
| 64 default='output') |
| 65 |
| 66 return parser |
| 67 |
| 68 |
| 69 def main(): |
| 70 # TODO(alessiob): level = logging.INFO once debugged. |
| 71 logging.basicConfig(level=logging.DEBUG) |
| 72 |
| 73 parser = _instance_arguments_parser() |
| 74 args = parser.parse_args() |
| 75 |
| 76 simulator = simulation.ApmModuleSimulator() |
| 77 simulator.run( |
| 78 config_filepaths=args.config_files, |
| 79 input_filepaths=args.input_files, |
| 80 noise_generator_names=args.noise_generators, |
| 81 eval_score_names=args.eval_scores, |
| 82 output_dir=args.output_dir) |
| 83 |
| 84 sys.exit(0) |
| 85 |
| 86 |
| 87 if __name__ == '__main__': |
| 88 main() |
OLD | NEW |