-
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
9278597
commit c5ceee2
Showing
14 changed files
with
857 additions
and
113 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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
*.pyc | ||
*.swp | ||
*.DS_Store | ||
*.egg-info | ||
.pit* | ||
/.run | ||
/werlog.js | ||
|
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
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,66 @@ | ||
#!/usr/bin/env python | ||
""" | ||
Tool for comparing two wav samples | ||
""" | ||
import sys | ||
import argparse | ||
|
||
from deepspeech_training.util.audio import AUDIO_TYPE_NP, mean_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 ({} and {})'.format(sample1.audio_format, sample2.audio_format)) | ||
if sample1.duration != sample2.duration: | ||
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 | ||
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) | ||
if CLI_ARGS.if_differ: | ||
if diff_dbfs <= CLI_ARGS.threshold: | ||
fail(equal_msg) | ||
if not CLI_ARGS.no_success_output: | ||
print(differ_msg, file=sys.stderr, flush=True) | ||
else: | ||
if diff_dbfs > CLI_ARGS.threshold: | ||
fail(differ_msg) | ||
if not CLI_ARGS.no_success_output: | ||
print(equal_msg, 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=-60.0, | ||
help="dB of sample deltas above which they are considered different") | ||
parser.add_argument( | ||
"--if-differ", | ||
action="store_true", | ||
help="If to succeed and return status code 0 on different signals and fail on equal ones (inverse check)." | ||
"This will still fail on different formats or durations.", | ||
) | ||
parser.add_argument( | ||
"--no-success-output", | ||
action="store_true", | ||
help="Stay silent on success (if samples are equal of - with --if-differ - samples are not equal)", | ||
) | ||
return parser.parse_args() | ||
|
||
|
||
if __name__ == "__main__": | ||
CLI_ARGS = handle_args() | ||
compare_samples() |
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
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,66 @@ | ||
#!/bin/sh | ||
|
||
set -xe | ||
|
||
ldc93s1_dir=`cd data/smoke_test; pwd` | ||
ldc93s1_csv="${ldc93s1_dir}/LDC93S1.csv" | ||
ldc93s1_wav="${ldc93s1_dir}/LDC93S1.wav" | ||
ldc93s1_overlay_csv="${ldc93s1_dir}/LDC93S1_overlay.csv" | ||
ldc93s1_overlay_wav="${ldc93s1_dir}/LDC93S1_reversed.wav" | ||
|
||
play="python bin/play.py --number 1 --quiet" | ||
compare="python bin/compare_samples.py --no-success-output" | ||
|
||
if [ ! -f "${ldc93s1_csv}" ]; then | ||
echo "Downloading and preprocessing LDC93S1 example data, saving in ${ldc93s1_dir}." | ||
python -u bin/import_ldc93s1.py ${ldc93s1_dir} | ||
fi; | ||
|
||
if [ ! -f "${ldc93s1_overlay_csv}" ]; then | ||
echo "Reversing ${ldc93s1_wav} to ${ldc93s1_overlay_wav}." | ||
sox "${ldc93s1_wav}" "${ldc93s1_overlay_wav}" reverse | ||
|
||
echo "Creating ${ldc93s1_overlay_csv}." | ||
printf "wav_filename\n${ldc93s1_overlay_wav}" > "${ldc93s1_overlay_csv}" | ||
fi; | ||
|
||
if ! $compare --if-differ "${ldc93s1_wav}" "${ldc93s1_overlay_wav}"; then | ||
echo "Sample comparison tool not working correctly" | ||
exit 1 | ||
fi | ||
|
||
$play ${ldc93s1_wav} --augment overlay[source="${ldc93s1_overlay_csv}",snr=20] --pipe >/tmp/overlay-test.wav | ||
if ! $compare --if-differ "${ldc93s1_wav}" /tmp/overlay-test.wav; then | ||
echo "Overlay augmentation had no effect or changed basic sample properties" | ||
exit 1 | ||
fi | ||
|
||
$play ${ldc93s1_wav} --augment reverb[delay=50.0,decay=2.0] --pipe >/tmp/reverb-test.wav | ||
if ! $compare --if-differ "${ldc93s1_wav}" /tmp/reverb-test.wav; then | ||
echo "Reverb augmentation had no effect or changed basic sample properties" | ||
exit 1 | ||
fi | ||
|
||
$play ${ldc93s1_wav} --augment gaps[n=10,size=100.0] --pipe >/tmp/gaps-test.wav | ||
if ! $compare --if-differ "${ldc93s1_wav}" /tmp/gaps-test.wav; then | ||
echo "Gaps augmentation had no effect or changed basic sample properties" | ||
exit 1 | ||
fi | ||
|
||
$play ${ldc93s1_wav} --augment resample[rate=4000] --pipe >/tmp/resample-test.wav | ||
if ! $compare --if-differ "${ldc93s1_wav}" /tmp/resample-test.wav; then | ||
echo "Resample augmentation had no effect or changed basic sample properties" | ||
exit 1 | ||
fi | ||
|
||
$play ${ldc93s1_wav} --augment codec[bitrate=4000] --pipe >/tmp/codec-test.wav | ||
if ! $compare --if-differ "${ldc93s1_wav}" /tmp/codec-test.wav; then | ||
echo "Codec augmentation had no effect or changed basic sample properties" | ||
exit 1 | ||
fi | ||
|
||
$play ${ldc93s1_wav} --augment volume --pipe >/tmp/volume-test.wav | ||
if ! $compare --if-differ "${ldc93s1_wav}" /tmp/volume-test.wav; then | ||
echo "Volume augmentation had no effect or changed basic sample properties" | ||
exit 1 | ||
fi |
Oops, something went wrong.