spectral_prosody/lib.rs
1//! # spectral-prosody
2//!
3//! Spectral graph methods for rhythmic prosody analysis.
4//!
5//! This crate maps speech/music prosody to a graph where nodes represent beats or syllables
6//! and edges represent temporal proximity. The graph Laplacian's spectrum reveals rhythmic
7//! patterns: low eigenvalues correspond to macro rhythm (large-scale phrasing), while high
8//! eigenvalues correspond to micro rhythm (fine-grained beat structure). Spectral clustering
9//! segments prosody into phrases.
10//!
11//! ## Quick Start
12//!
13//! ```rust
14//! use spectral_prosody::{ProsodyNode, ProsodyGraph, RhythmExtractor, PhraseSegmenter};
15//!
16//! // Create prosody nodes from timing/energy/pitch data
17//! let nodes: Vec<ProsodyNode> = (0..8)
18//! .map(|i| ProsodyNode::new(i as f64 * 0.5, 1.0, 220.0 + i as f64 * 5.0, 0.25, 3000.0))
19//! .collect();
20//!
21//! // Build a k-nearest-neighbor graph
22//! let graph = ProsodyGraph::build_knn(nodes, 3, 1.0).unwrap();
23//!
24//! // Extract rhythmic layers via spectral decomposition
25//! let extractor = RhythmExtractor::new(5);
26//! let layers = extractor.extract(&graph).unwrap();
27//!
28//! // Segment into phrases using the Fiedler vector
29//! let segmenter = PhraseSegmenter::new(4);
30//! let phrases = segmenter.segment(&graph).unwrap();
31//! ```
32
33pub mod error;
34pub mod feature;
35pub mod midi;
36pub mod phrase;
37pub mod prosody;
38pub mod rhythm;
39
40pub use error::ProsodyError;
41pub use feature::{ProsodyFeature, estimate_pitch};
42pub use midi::{MidiNote, frequency_to_midi, midi_to_frequency, layers_to_midi, notes_to_csv};
43pub use phrase::{Phrase, PhraseSegmenter};
44pub use prosody::{ProsodyGraph, ProsodyNode, graph_from_features};
45pub use rhythm::{RhythmExtractor, RhythmLayer, algebraic_connectivity};