Skip to content

Instantly share code, notes, and snippets.

@benpye
Created August 4, 2024 22:27
Show Gist options
  • Save benpye/9b4e2edcd0328f9f1e91a847498d6135 to your computer and use it in GitHub Desktop.
Save benpye/9b4e2edcd0328f9f1e91a847498d6135 to your computer and use it in GitHub Desktop.
#!/bin/sh
target_sample_rate="48000"
target_bit_depth="16"
sample_rate=$(soxi -r "$1")
bit_depth=$(soxi -b "$1")
if [ "$sample_rate" -le "$target_sample_rate" ] && [ "$bit_depth" -le "$target_bit_depth" ]; then
cp "$1" "$2"
else
if [ "$sample_rate" -lt "$target_sample_rate" ]; then
target_sample_rate="$sample_rate"
elif [ "$sample_rate" -eq "88200" ] || [ "$sample_rate" -eq "176400" ] || [ "$sample_rate" -eq "352800" ]; then
target_sample_rate="44100"
fi
sox "$1" -G -b $target_bit_depth -r $target_sample_rate "$2"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment