This repository was archived by the owner on Jun 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Live augmentation #2897
Merged
Merged
Live augmentation #2897
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9278597
Named tuple AudioFormat, parameter re-ordering in util.audio and NP t…
tilmankamp c5ceee2
Live audio augmentation
tilmankamp 64e1488
Apply suggestions from code review
tilmankamp a5303cc
Renamed prepare_samples to augment_samples
tilmankamp 7b08e59
Value range unit tests
tilmankamp 96caa2d
Follow up on PR comments
tilmankamp ac9a17d
Moved signal augmentation tests to own test config
tilmankamp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.