Sha256: 013b2f0f6e84683310679bd89ee39d0ff1a84572c604d3fc4cfd1cb8473ed875
Contents?: true
Size: 1.5 KB
Versions: 1
Compression:
Stored size: 1.5 KB
Contents
require 'scissor' require 'echonest' require 'scissor/echonest/chunk_ext.rb' module Scissor def self.echonest_api_key=(echonest_api_key) Scissor::Chunk.echonest_api_key = echonest_api_key end class Chunk class << self attr_accessor :echonest_api_key def echonest @echonest ||= Echonest(echonest_api_key) end end def beats tempfile_for_echonest do |tmpfile| chunks = [] scissor = to_file(tmpfile, :bitrate => '64k') beats = self.class.echonest.get_beats(tmpfile) if beats.size != 0 chunk = self[0, beats.first.start] beat = Beat.new(beats.first.start, 1.0) chunk.set_delegate(beat) chunks << chunk end beats.inject do |m, beat| chunk = self[m.start, beat.start - m.start] chunk.set_delegate(m) chunks << chunk beat end chunks end end def segments tempfile_for_echonest do |tmpfile| scissor = to_file(tmpfile, :bitrate => '64k') segments = self.class.echonest.get_segments(tmpfile) segments.inject([]) do |chunks, segment| chunk = self[segment.start, segment.duration] chunk.set_delegate(segment) chunks << chunk chunks end end end private def tempfile_for_echonest tmpfile = Pathname.new('/tmp/scissor_echonest_temp_' + $$.to_s + '.mp3') yield tmpfile ensure tmpfile.unlink end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
scissor-echonest-0.0.7 | lib/scissor/echonest.rb |