Skip to content

Instantly share code, notes, and snippets.

@utahka
Last active December 6, 2015 03:05
Show Gist options
  • Save utahka/244e44bd6b4652e29b1a to your computer and use it in GitHub Desktop.
Save utahka/244e44bd6b4652e29b1a to your computer and use it in GitHub Desktop.
#!/bin/sh
file_name=${1:?File name is not set}
base_name=`basename ${file_name} .wav`
interval=${2:-1}
duration=`soxi ${file_name} | awk '/Duration/ {print $3}' | tr ':.' ' '`
hour=`echo ${duration} | awk '{print $1}'`
minute=`echo ${duration} | awk '{print $2}'`
second=`echo ${duration} | awk '{print $3}'`
max_num=$(( (hour * 3600 + minute * 60 + second) / interval ))
echo "Divide ${file_name} into ${max_num} parts"
for ((start=0; start < max_num; start++)) {
end=`printf %05d $((start + 1))`
sox ${file_name} ./parts/${base_name}_${end}.wav trim ${start} ${interval}
}
@utahka
Copy link
Author

utahka commented Dec 6, 2015

trim

trim divide a wav file to any number of parts.

dependance

  • SoX

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment