Generate APM-QA annotations for noise mixes.

The APM-QA tool produces clean-speech + noise + echo mixes with the
--additive_noise_tracks_path, --test_data_generators,
--echo_path_simulator flags. From this CL, it automatically produces
compressed Numpy annotations for the mixes. Annotations are placed in
the same  folder as the mixes with name '${basename}-annotations.npz'.

TBR=alessiob@webrtc.org
NOTRY=True

Bug: webrtc:7494
Change-Id: I71941a4283594ef813de3ed65be31623bce5d7de
Reviewed-on: https://webrtc-review.googlesource.com/24960
Commit-Queue: Alex Loiko <aleloi@webrtc.org>
Reviewed-by: Alex Loiko <aleloi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20844}
This commit is contained in:
Alex Loiko
2017-11-23 11:06:48 +01:00
committed by Commit Bot
parent 6f36747fb1
commit 02d71fde8d
3 changed files with 25 additions and 11 deletions

View File

@ -58,7 +58,7 @@ class AudioAnnotationsExtractor(object):
vads.append("apm")
return "VadType({})".format(", ".join(vads))
_OUTPUT_FILENAME = 'annotations.npz'
_OUTPUT_FILENAME_TEMPLATE = '{}annotations.npz'
# Level estimation params.
_ONE_DB_REDUCTION = np.power(10.0, -1.0 / 20.0)
@ -112,8 +112,8 @@ class AudioAnnotationsExtractor(object):
self._VAD_WEBRTC_APM_PATH
@classmethod
def GetOutputFileName(cls):
return cls._OUTPUT_FILENAME
def GetOutputFileNameTemplate(cls):
return cls._OUTPUT_FILENAME_TEMPLATE
def GetLevel(self):
return self._level
@ -177,13 +177,15 @@ class AudioAnnotationsExtractor(object):
for extvad_name in self._external_vads:
self._external_vads[extvad_name].Run(filepath)
def Save(self, output_path):
def Save(self, output_path, annotation_name=""):
ext_kwargs = {'extvad_conf-' + ext_vad:
self._external_vads[ext_vad].GetVadOutput()
for ext_vad in self._external_vads}
# pylint: disable=star-args
np.savez_compressed(
file=os.path.join(output_path, self._OUTPUT_FILENAME),
file=os.path.join(
output_path,
self.GetOutputFileNameTemplate().format(annotation_name)),
level=self._level,
level_frame_size=self._level_frame_size,
level_frame_size_ms=self._LEVEL_FRAME_SIZE_MS,

View File

@ -111,9 +111,11 @@ class TestAnnotationsExtraction(unittest.TestCase):
def testSaveLoad(self):
e = annotations.AudioAnnotationsExtractor(self._ALL_VAD_TYPES)
e.Extract(self._wav_file_path)
e.Save(self._tmp_path)
e.Save(self._tmp_path, "fake-annotation")
data = np.load(os.path.join(self._tmp_path, e.GetOutputFileName()))
data = np.load(os.path.join(
self._tmp_path,
e.GetOutputFileNameTemplate().format("fake-annotation")))
np.testing.assert_array_equal(e.GetLevel(), data['level'])
self.assertEqual(np.float32, data['level'].dtype)
np.testing.assert_array_equal(
@ -146,8 +148,10 @@ class TestAnnotationsExtraction(unittest.TestCase):
vad_type_value,
{'fake': FakeExternalFactory()})
e.Extract(self._wav_file_path)
e.Save(self._tmp_path)
data = np.load(os.path.join(self._tmp_path, e.GetOutputFileName()))
e.Save(self._tmp_path, annotation_name="fake-annotation")
data = np.load(os.path.join(
self._tmp_path,
e.GetOutputFileNameTemplate().format("fake-annotation")))
self.assertEqual(np.float32, data['extvad_conf-fake'].dtype)
np.testing.assert_almost_equal(np.arange(100, dtype=np.float32),
data['extvad_conf-fake'])

View File

@ -271,9 +271,10 @@ class ApmModuleSimulator(object):
input_signal_filepath, signal)
data_access.Metadata.SaveFileMetadata(input_signal_filepath, metadata)
def _ExtractCaptureAnnotations(self, input_filepath, output_path):
def _ExtractCaptureAnnotations(self, input_filepath, output_path,
annotation_name=""):
self._annotator.Extract(input_filepath)
self._annotator.Save(output_path)
self._annotator.Save(output_path, annotation_name)
def _Simulate(self, test_data_generators, clean_capture_input_filepath,
render_input_filepath, test_data_cache_path,
@ -337,6 +338,13 @@ class ApmModuleSimulator(object):
echo_test_data_cache_path, noisy_capture_input_filepath,
echo_path_filepath)
# Extract annotations for the APM input mix.
apm_input_basepath, apm_input_filename = os.path.split(
apm_input_filepath)
self._ExtractCaptureAnnotations(
apm_input_filepath, apm_input_basepath,
os.path.splitext(apm_input_filename)[0] + '-')
# Simulate a call using APM.
self._audioproc_wrapper.Run(
config_filepath=config_filepath,