Skip to content

Instantly share code, notes, and snippets.

@fgnass
Created May 31, 2018 14:19
Show Gist options
  • Save fgnass/7c619efa5fcfcaba415177632168731c to your computer and use it in GitHub Desktop.
Save fgnass/7c619efa5fcfcaba415177632168731c to your computer and use it in GitHub Desktop.
Convert wav into mp3 files suitable for Alexa and Google Actions
#!/bin/bash
set -e
# Rename files to make them URL friendly
# https://formulae.brew.sh/formula/slugify
slugify *
# Trim silence at the beginning
# https://formulae.brew.sh/formula/sox
mkdir trimmed
for i in *.wav; do sox "$i" trimmed/"$i" silence 1 0.1 1% ; done
cd trimmed
# Convert to 24k for Google
# https://formulae.brew.sh/formula/ffmpeg
mkdir 24k
for i in *.wav; do ffmpeg -i "$i" -ac 2 -codec:a libmp3lame -b:a 96k -ar 24000 24k/"$(basename "$i" .wav)".mp3 ; done
# Convert to 16k for Alexa and normalize volume
# https://github.com/slhck/ffmpeg-normalize
mkdir 16k
ffmpeg-normalize *.wav -c:a libmp3lame -ar 16000 -b 48k -t -14 -of 16k --extension mp3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment