Last active
July 5, 2023 19:43
-
-
Save tsointsoin/6bfa89f4c54a77a564d02c4c237a724a to your computer and use it in GitHub Desktop.
Bash script to prepare samples for Expert sleepers Disting - Needs the following utilities : detox, ffmpeg and sox
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
| #!/bin/bash | |
| # | |
| # Convert samples to 44.1kHz/16bit | |
| # Remove all metadata from wav files in folders and create reversed wav files | |
| # Needed : detox, sox and ffmpeg | |
| # | |
| # Usage: | |
| # Put this script in a folder with your samples (they can be in subfolders), chmod +x | |
| # and execute ./prepare_disting.sh | |
| # All .wav files will be treated, detox will take care of spaces and such things | |
| # Be aware that THIS SCRIPT MAKES NO BACKUP, so work on copies | |
| # | |
| # Do we have what we need ? | |
| if ! [[ $(which sox) ]]; then | |
| echo "sox executable not found on system, exiting" | |
| exit 0 | |
| fi | |
| if ! [[ $(which ffmpeg) ]]; then | |
| echo "ffmpeg executable not found on system, exiting" | |
| exit 0 | |
| fi | |
| if ! [[ $(which detox) ]]; then | |
| echo "detox executable not found on system, exiting" | |
| exit 0 | |
| fi | |
| # Use sox to convert samples to 16bit/44100Hz | |
| # Original samples are deleted | |
| convert_16b44khz () { | |
| filename="$1" | |
| sample_rate=$(sox --i -r $filename) | |
| sample_depth=$(sox --i -p $filename) | |
| if [[ "$sample_depth" != 16 || "$sample_rate" != 44100 ]]; then | |
| newname=${filename%.wav}_s.wav | |
| sox $filename -r 44100 -b 16 $newname | |
| rm $filename | |
| mv $newname $filename | |
| echo "Sample "$filename" converted to 16bit/44.1kHz" | |
| else | |
| echo "Not converting "$filename | |
| fi | |
| } | |
| # Use ffmpeg to remove metadata from samples | |
| # Original samples are deleted | |
| remove_metadata () { | |
| filename="$1" | |
| newname=${filename%.wav}_s.wav | |
| ffmpeg -hide_banner -loglevel warning -y -i $filename -map_metadata -1 -codec copy $newname | |
| rm $filename | |
| mv $newname $filename | |
| echo "Metadata removed from sample "$filename | |
| } | |
| # Use sox to reverse samples | |
| # For each sample found a copy is created with "reversed" added to its name | |
| # Eg: if the sample is named "cymbal.wav" then a reversed copy "cymbal.wav.reversed" is created | |
| reverse_audio () { | |
| filename="$1" | |
| reversed=${filename}.reversed | |
| if [ ! -f "$reversed" ] | |
| then | |
| newname=${filename}.reversed.wav | |
| sox $filename $newname reverse | |
| mv $newname ${newname%.wav} | |
| else | |
| echo $reversed" already exists !" | |
| fi | |
| } | |
| export -f convert_16b44khz | |
| export -f remove_metadata | |
| export -f reverse_audio | |
| detox -r * | |
| find . -type f -name "*.wav" -exec bash -c 'convert_16b44khz "$0"' {} \; | |
| find . -type f -name "*.wav" -exec bash -c 'remove_metadata "$0"' {} \; | |
| find . -type f -name "*.wav" -exec bash -c 'reverse_audio "$0"' {} \; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment