Skip to content

Instantly share code, notes, and snippets.

@mthrok
Created February 11, 2021 00:05
Show Gist options
  • Save mthrok/05cd061c8a55612cb78b73aa63c20b13 to your computer and use it in GitHub Desktop.
Save mthrok/05cd061c8a55612cb78b73aa63c20b13 to your computer and use it in GitHub Desktop.
Generate various audio formats with sox, changing parameters
#!/usr/bin/env bash
base_dir="tmp/test_sox"
mkdir -p "${base_dir}"
base_file="${base_dir}/base.wav"
sox --rate 8000 --channels 1 --null "${base_file}" synth 1 sawtooth 1
for type in wav mp3 flac vorbis sph amr-nb amb gsm htk; do
for encoding in no_encoding signed-integer unsigned-integer floating-point mu-law a-law; do
prefix="${base_dir}/${type}/${encoding}"
mkdir -p "${prefix}"
for bits in no_bits 8 16 24 32; do
filepath="${prefix}/${bits}.${type}"
printf "%s\n" "${filepath}"
options=(--type "${type}")
if [ "${encoding}" != "no_encoding" ]; then
options+=(--encoding "${encoding}")
fi
if [ "${bits}" != "no_bits" ]; then
options+=(--bits "${bits}")
fi
sox "${base_file}" --rate 8000 --channels 1 "${options[@]}" "${filepath}" 2>&1 # | grep WARN | grep -v 'dither'
done
soxi "${prefix}/"* | grep 'Input File\|bit'
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment