1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//! Split long PCM audio into pieces that never exceed a maximum length, cutting in silence, or at
//! the quietest spot when there is none. No model, no FFmpeg, and every position is a sample index
//! in the original timeline.
//!
//! 1. [`Analyzer`] turns PCM of any sample rate into frame levels ([`Analysis`]). Scores from an
//! external voice activity detector can be used instead with [`Analysis::from_scores`].
//! 2. [`Analysis::segments`] finds silence and sound, and [`Analysis::trim`] the audio between the
//! first and last sound.
//! 3. [`plan`] chooses cuts over the whole file under minimum, target and maximum piece lengths.
//! [`adjust`] instead moves cut points you already have into nearby silence.
//!
//! ```
//! use core::time::Duration;
//! use silence_split::{AnalyzeConfig, Analyzer, Gap, Layout, PlanConfig, SegmentConfig, plan};
//!
//! # fn main() -> Result<(), silence_split::ConfigError> {
//! let layout = Layout { sample_rate: 16_000, channels: 1 };
//! let mut analyzer = Analyzer::new(layout, &AnalyzeConfig::default())?;
//! # let pcm: Vec<f32> = (0..16_000 * 20)
//! # .map(|i| if (i / 16_000) % 5 == 4 { 0.0 } else { 0.3 * (i as f32 * 0.07).sin() })
//! # .collect();
//! analyzer.push_interleaved(&pcm);
//! let analysis = analyzer.finish();
//!
//! let config = PlanConfig::new(Duration::from_secs(2), Duration::from_secs(8), Duration::from_secs(10))?
//! .gap(Gap::Drop);
//! let plan = plan(&analysis, &SegmentConfig::default(), &config);
//! for piece in &plan.pieces {
//! let _samples = &pcm[piece.start as usize..piece.end as usize];
//! assert!(piece.end - piece.start <= 160_000);
//! }
//! # Ok(())
//! # }
//! ```
//!
//! # Features
//!
//! - `std` (default): uses the standard library's floating-point functions. Without it the crate
//! is `no_std` with `alloc` and needs the `libm` feature.
//! - `libm`: floating-point functions for `no_std`.
//! - `serde`: `Serialize` and `Deserialize` for [`Analysis`], [`Plan`] and the result types.
//! Deserializing an [`Analysis`] validates it.
extern crate alloc;
extern crate std;
compile_error!;
pub use ;
pub use ;
pub use ConfigError;
pub use write_audacity_labels;
pub use ;
pub use ;
pub use ;
;