Skip to content

Instantly share code, notes, and snippets.

@youpy
Created October 18, 2009 11:04
Show Gist options
  • Select an option

  • Save youpy/212631 to your computer and use it in GitHub Desktop.

Select an option

Save youpy/212631 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'pit'
require 'scissor/echonest'
config = Pit.get('echonest.com', :require => {
'api_key' => 'your Echo Nest API key'
})
Scissor.echonest_api_key = config['api_key']
Scissor.logger.level = Logger::DEBUG
def main
if ARGV.size != 2
puts "usage: #$0 srcfile outfile"
exit
end
flatten(ARGV[0]) >> ARGV[1]
end
def avarage_duration(chunks)
chunks.inject(0) do |total, chunk|
total + chunk.duration
end / chunks.size.to_f
end
def flatten(srcfile)
beats = Scissor(srcfile).beats
avarage_duration = avarage_duration(beats)
Scissor.join(beats.map do |beat|
beat.pitch(beat.duration / avarage_duration * 100)
end)
end
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment