Class: Wavesync::EssentiaBpmDetector
- Inherits:
-
Object
- Object
- Wavesync::EssentiaBpmDetector
- Defined in:
- lib/wavesync/essentia_bpm_detector.rb
Constant Summary collapse
- PYTHON_SCRIPT =
<<~PYTHON import essentia, essentia.streaming as ess, json, sys pool = essentia.Pool() loader = ess.MonoLoader(filename=sys.argv[1], sampleRate=44100) rhythm = ess.RhythmDescriptors() loader.audio >> rhythm.signal rhythm.bpm >> (pool, 'bpm') rhythm.confidence >> (pool, 'confidence') essentia.run(loader) print(json.dumps({'bpm': round(float(pool['bpm'])), 'confidence': round(float(pool['confidence']), 2)})) PYTHON
Class Method Summary collapse
-
.available? ⇒ Boolean
: () -> bool?.
-
.detect(file_path) ⇒ Object
: (String file_path) -> Integer, confidence: Float?.
Class Method Details
.available? ⇒ Boolean
: () -> bool?
22 23 24 |
# File 'lib/wavesync/essentia_bpm_detector.rb', line 22 def self.available? PythonVenv.essentia_available? end |
.detect(file_path) ⇒ Object
: (String file_path) -> Integer, confidence: Float?
27 28 29 30 31 32 33 34 |
# File 'lib/wavesync/essentia_bpm_detector.rb', line 27 def self.detect(file_path) output = PythonVenv.run_script(PYTHON_SCRIPT, file_path) data = JSON.parse(output.strip) bpm = data['bpm'].to_f bpm.positive? ? { bpm: bpm.round, confidence: data['confidence'].to_f } : nil rescue StandardError nil end |