1# Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
2#
3# Use of this source code is governed by a BSD-style license
4# that can be found in the LICENSE file in the root of the source
5# tree. An additional intellectual property rights grant can be found
6# in the file PATENTS.  All contributing project authors may
7# be found in the AUTHORS file in the root of the source tree.
8
9"""Evaluator of the APM module.
10"""
11
12import logging
13
14
15class ApmModuleEvaluator(object):
16  """APM evaluator class.
17  """
18
19  def __init__(self):
20    pass
21
22  @classmethod
23  def Run(cls, evaluation_score_workers, apm_input_metadata,
24          apm_output_filepath, reference_input_filepath, output_path):
25    """Runs the evaluation.
26
27    Iterates over the given evaluation score workers.
28
29    Args:
30      evaluation_score_workers: list of EvaluationScore instances.
31      apm_input_metadata: dictionary with metadata of the APM input.
32      apm_output_filepath: path to the audio track file with the APM output.
33      reference_input_filepath: path to the reference audio track file.
34      output_path: output path.
35
36    Returns:
37      A dict of evaluation score name and score pairs.
38    """
39    # Init.
40    scores = {}
41
42    for evaluation_score_worker in evaluation_score_workers:
43      logging.info('   computing <%s> score', evaluation_score_worker.NAME)
44      evaluation_score_worker.SetInputSignalMetadata(apm_input_metadata)
45      evaluation_score_worker.SetReferenceSignalFilepath(
46          reference_input_filepath)
47      evaluation_score_worker.SetTestedSignalFilepath(
48          apm_output_filepath)
49
50      evaluation_score_worker.Run(output_path)
51      scores[evaluation_score_worker.NAME] = evaluation_score_worker.score
52
53    return scores
54