Skip to content

Instantly share code, notes, and snippets.

@WilCF
Created February 25, 2014 18:49
Show Gist options
  • Save WilCF/9215134 to your computer and use it in GitHub Desktop.
Save WilCF/9215134 to your computer and use it in GitHub Desktop.
There's a script you can run that divides an audio clip into small segments.
The following code splits an mpeg into optionally overlapping snippets of audio for transcription or whatever...
#NOTE! you must install ffmpeg in your system first (http://ffmpeg.org/download.html): $brew install FFmpeg
overlap = XX #overlap between snippets in seconds
total_length = XX #total length of file in seconds
step_size = XX #length of snippets in seconds
file_path = "" #path to audio file
file_name = File.basename(file_path, '.*')
(0..total_length).step(step_size) { |x| `ffmpeg -ss #{x-overlap} -i #{file_path} -c copy -t #{step_size+overlap} #{file_name}-out-#{x}.mp3` }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment