-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1913765
commit 0a331f0
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env python | ||
""" | ||
Tool for comparing two wav samples | ||
""" | ||
import sys | ||
import argparse | ||
|
||
from deepspeech_training.util.audio import AUDIO_TYPE_NP, compute_dbfs | ||
from deepspeech_training.util.sample_collections import load_sample | ||
|
||
|
||
def fail(message): | ||
print(message, file=sys.stderr, flush=True) | ||
sys.exit(1) | ||
|
||
|
||
def compare_samples(): | ||
sample1 = load_sample(CLI_ARGS.sample1) | ||
sample2 = load_sample(CLI_ARGS.sample2) | ||
if sample1.audio_format != sample2.audio_format: | ||
fail('Samples differ on: audio-format') | ||
if sample1.duration != sample2.duration: | ||
fail('Samples differ on: duration') | ||
sample1.change_audio_type(AUDIO_TYPE_NP) | ||
sample2.change_audio_type(AUDIO_TYPE_NP) | ||
audio_diff = sample1.audio - sample2.audio | ||
dbfs, _ = compute_dbfs(audio_diff) | ||
if dbfs > CLI_ARGS.threshold: | ||
fail('Samples differ on: sample data ({:0.2f} dB difference) '.format(dbfs)) | ||
print('Samples are considered equal ({:0.2f} dB difference)'.format(dbfs), file=sys.stderr, flush=True) | ||
|
||
|
||
def handle_args(): | ||
parser = argparse.ArgumentParser( | ||
description="Tool for checking similarity of two samples" | ||
) | ||
parser.add_argument("sample1", help="Filename of sample 1 to compare") | ||
parser.add_argument("sample2", help="Filename of sample 2 to compare") | ||
parser.add_argument("--threshold", type=float, default=-50.0, | ||
help="Maximum dB difference of samples before they are considered different") | ||
return parser.parse_args() | ||
|
||
|
||
if __name__ == "__main__": | ||
CLI_ARGS = handle_args() | ||
compare_samples() |