Crate bliss_audio
source · [−]Expand description
bliss audio library
bliss is a library for making “smart” audio playlists.
The core of the library is the Song object, which relates to a
specific analyzed song and contains its path, title, analysis, and
other metadata fields (album, genre…).
Analyzing a song is as simple as running Song::from_path("/path/to/song")
.
The analysis field of each song is an array of f32, which makes the comparison between songs easy, by just using e.g. euclidean distance (see distance for instance).
Once several songs have been analyzed, making a playlist from one Song is as easy as computing distances between that song and the rest, and ordering the songs by distance, ascending.
If you want to implement a bliss plugin for an already existing audio player, the [Library] struct is a collection of goodies that should prove useful (it contains utilities to store analyzed songs in a self-contained database file, to make playlists directly from the database, etc). blissify for both an example of how the [Library] struct works, and a real-life demo of bliss implemented for MPD.
Examples
Analyze & compute the distance between two songs
use bliss_audio::{BlissResult, Song};
fn main() -> BlissResult<()> {
let song1 = Song::from_path("/path/to/song1")?;
let song2 = Song::from_path("/path/to/song2")?;
println!("Distance between song1 and song2 is {}", song1.distance(&song2));
Ok(())
}
Make a playlist from a song, discarding failed songs
use bliss_audio::{
analyze_paths,
playlist::{closest_to_first_song, euclidean_distance},
BlissResult, Song,
};
fn main() -> BlissResult<()> {
let paths = vec!["/path/to/song1", "/path/to/song2", "/path/to/song3"];
let mut songs: Vec<Song> = analyze_paths(&paths).filter_map(|(_, s)| s.ok()).collect();
// Assuming there is a first song
let first_song = songs.first().unwrap().to_owned();
closest_to_first_song(&first_song, &mut songs, euclidean_distance);
println!("Playlist is:");
for song in songs {
println!("{}", song.path.display());
}
Ok(())
}
Modules
Structs
Enums
Constants
Analysis
Functions
paths
, and return the analyzed Song objects through an
mpsc::IntoIter. number_cores
sets the number of cores the analysis
will use, capped by your system’s capacity. Most of the time, you want to
use the simpler analyze_paths
functions, which autodetects the number
of cores in your system.