From f2e57467c6774f26d525f66cca3ec5953d6c2d33 Mon Sep 17 00:00:00 2001 From: Reuben Morais Date: Mon, 18 Jan 2021 13:57:56 +0000 Subject: [PATCH] Compare sample durations with an epsilon --- bin/compare_samples.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bin/compare_samples.py b/bin/compare_samples.py index 27898cd1..19a60575 100755 --- a/bin/compare_samples.py +++ b/bin/compare_samples.py @@ -4,6 +4,7 @@ Tool for comparing two wav samples """ import sys import argparse +import numpy as np from deepspeech_training.util.audio import AUDIO_TYPE_NP, mean_dbfs from deepspeech_training.util.sample_collections import load_sample @@ -19,11 +20,15 @@ def compare_samples(): sample2 = load_sample(CLI_ARGS.sample2).unpack() if sample1.audio_format != sample2.audio_format: fail('Samples differ on: audio-format ({} and {})'.format(sample1.audio_format, sample2.audio_format)) - if sample1.duration != sample2.duration: + if abs(sample1.duration - sample2.duration) > 0.001: fail('Samples differ on: duration ({} and {})'.format(sample1.duration, sample2.duration)) sample1.change_audio_type(AUDIO_TYPE_NP) sample2.change_audio_type(AUDIO_TYPE_NP) - audio_diff = sample1.audio - sample2.audio + samples = [sample1, sample2] + largest = np.argmax([sample1.audio.shape[0], sample2.audio.shape[0]]) + smallest = (largest + 1) % 2 + samples[largest].audio = samples[largest].audio[:len(samples[smallest].audio)] + audio_diff = samples[largest].audio - samples[smallest].audio diff_dbfs = mean_dbfs(audio_diff) differ_msg = 'Samples differ on: sample data ({:0.2f} dB difference) '.format(diff_dbfs) equal_msg = 'Samples are considered equal ({:0.2f} dB difference)'.format(diff_dbfs)