Skip to main content

EmbeddingExtractor

Trait EmbeddingExtractor 

Source
pub trait EmbeddingExtractor: Send + Sync {
    // Required methods
    fn extract(
        &self,
        samples: &[f32],
        config: &DiarizationConfig,
    ) -> Result<Vec<f32>, EmbeddingError>;
    fn embedding_dim(&self) -> usize;
}
Expand description

Trait for speaker embedding extractors.

Implementors are expected to be thread-safe (either internally synchronized or cheaply clonable), so that they can be shared across concurrent diarizers.

use polyvoice::{EmbeddingExtractor, DummyExtractor, DiarizationConfig};
let extractor = DummyExtractor::new(256);
let config = DiarizationConfig::default();
let samples = vec![0.0f32; config.window_samples()];
let emb = extractor.extract(&samples, &config).unwrap();
assert_eq!(emb.len(), 256);

Required Methods§

Source

fn extract( &self, samples: &[f32], config: &DiarizationConfig, ) -> Result<Vec<f32>, EmbeddingError>

Extract an embedding from raw 16 kHz (or config.sample_rate) mono f32 samples.

The caller is responsible for ensuring the buffer length matches the model expectations (usually config.window_samples()). Implementations may pad or truncate, but should prefer returning an error when the input is unusable.

Source

fn embedding_dim(&self) -> usize

Dimensionality of the produced embedding vectors.

Implementors§