Crates.io | beat-detector |
lib.rs | beat-detector |
version | 0.1.2 |
source | src |
created_at | 2021-04-05 12:13:15.284369 |
updated_at | 2021-09-12 12:47:55.41305 |
description | Audio beat detection library, that supports different audio input devices as source. You can pass a callback for each found beat to the library. |
homepage | https://github.com/phip1611/beat-detector |
repository | https://github.com/phip1611/beat-detector |
max_upload_size | |
id | 379286 |
size | 2,039,774 |
This is a Rust library that enables beat detection on live audio data input. One use case is that you have an audio/aux-splitter on your computer where one end goes into the sound system whereas the other goes into the microphone input of a Raspberry Pi.
The crate provides multiple strategies that you can connect to the audio source. So far it offers two strategies:
I'm not an expert in audio analysis, but I'm proud what I achieved so far with the spectrum strategy. This library needs a more "bulletproof" strategy, to cope with complex and fast songs.
Here's a demo I recorded in my room. Of course, it was synced to music, when I recorded it. :)
Cargo.toml
beat-detector = "<latest version>"
code.rs
(also see examples/
in repository!)
//! Minimum example on how to use this library. Sets up the "callback loop".
use cpal::Device;
use beat_detector::StrategyKind;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
/// Minimum example on how to use this library. Sets up the "callback loop".
fn main() {
let recording = Arc::new(AtomicBool::new(true));
let recording_cpy = recording.clone();
ctrlc::set_handler(move || {
eprintln!("Stopping recording");
recording_cpy.store(false, Ordering::SeqCst);
}).unwrap();
let dev = select_input_device();
let strategy = select_strategy();
let on_beat = |info| {
println!("Found beat at {:?}ms", info);
};
// actually start listening in thread
let handle = beat_detector::record::start_listening(
on_beat,
Some(dev),
strategy,
recording,
).unwrap();
handle.join().unwrap();
}
fn select_input_device() -> Device {
// todo implement user selection
beat_detector::record::audio_input_device_list().into_iter().next().expect("At least one audio input device must be available.").1
}
fn select_strategy() -> StrategyKind {
// todo implement user selection
StrategyKind::Spectrum
}
1.52.1 stable