pub trait Embedder: Send + Sync {
// Required methods
fn dim(&self) -> usize;
fn embed(&self, audio: &[f32]) -> Result<Vec<f32>, EmbedderError>;
// Provided method
fn embed_batch(
&self,
audios: &[&[f32]],
) -> Result<Vec<Vec<f32>>, EmbedderError> { ... }
}Expand description
Speaker embedding extractor — turns a slice of 16 kHz mono audio into a fixed-dimension embedding vector. Implementations are expected to L2-normalize their output so cosine similarity is a meaningful metric downstream.
This is the supported library injection API for
crate::pipeline::LegacyPipeline and
crate::streaming::StreamingPipeline. Implement it on an external
encoder (Candle, tract, custom) without enabling onnx:
use polyvoice::{Embedder, EmbedderError};
struct ConstantEmbedder { dim: usize }
impl Embedder for ConstantEmbedder {
fn dim(&self) -> usize { self.dim }
fn embed(&self, _audio: &[f32]) -> Result<Vec<f32>, EmbedderError> {
let mut v = vec![0.0f32; self.dim];
if let Some(first) = v.first_mut() { *first = 1.0; }
Ok(v)
}
}Required Methods§
Provided Methods§
Sourcefn embed_batch(&self, audios: &[&[f32]]) -> Result<Vec<Vec<f32>>, EmbedderError>
fn embed_batch(&self, audios: &[&[f32]]) -> Result<Vec<Vec<f32>>, EmbedderError>
Compute embeddings for a batch of audio segments. Default implementation is sequential; impls may override with a true batched ONNX call.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".