Class: Wavesync::PercivalBpmDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/wavesync/percival_bpm_detector.rb

Constant Summary collapse

PYTHON_SCRIPT =
<<~PYTHON
  import essentia.standard as es, sys
  audio = es.MonoLoader(filename=sys.argv[1], sampleRate=44100)()
  bpm = es.PercivalBpmEstimator()(audio)
  print(round(float(bpm)))
PYTHON

Class Method Summary collapse

Class Method Details

.available?Boolean

: () -> bool?

Returns:

  • (Boolean)


16
17
18
# File 'lib/wavesync/percival_bpm_detector.rb', line 16

def self.available?
  PythonVenv.essentia_available?
end

.detect(file_path) ⇒ Object

: (String file_path) -> Integer?



21
22
23
24
25
26
27
# File 'lib/wavesync/percival_bpm_detector.rb', line 21

def self.detect(file_path)
  output = PythonVenv.run_script(PYTHON_SCRIPT, file_path)
  bpm = output.strip.to_f
  bpm.positive? ? bpm.round : nil
rescue StandardError
  nil
end