pub struct Endpointer<V> { /* private fields */ }Available on non-
target_family=wasm only.Expand description
Finds utterances in a stream. Speech opens on a frame scored at or above
SPEECH_THRESHOLD and closes once silence has lasted trailing_silence.
After an End it keeps listening, so the next Start opens the next
utterance. An utterance still open when input ends gets no End.
Positions count from the first push. To land them on a
RecordingReader that did not start at
zero, add its held_from() at that push. Start has no lead-in: open an
utterance LEAD_IN_FRAMES frames earlier to cut
as the microphone does.
fn utterances<V: VoiceActivityDetector>(
vad: &mut V,
batches: &[Vec<i16>],
) -> Result<(), VoiceActivityError> {
// `&mut V` leaves the loaded detector with the caller for the next run.
let mut endpointer = Endpointer::new(vad, SilenceDuration::default());
for batch in batches {
for boundary in endpointer.push(batch)? {
match boundary {
Boundary::Start(at) => println!("speech from sample {at}"),
Boundary::End(at) => println!("utterance ends at sample {at}"),
}
}
}
Ok(())
}Implementations§
Source§impl<V: VoiceActivityDetector> Endpointer<V>
impl<V: VoiceActivityDetector> Endpointer<V>
Sourcepub fn new(vad: V, trailing_silence: SilenceDuration) -> Self
pub fn new(vad: V, trailing_silence: SilenceDuration) -> Self
Resets vad, so state from earlier audio does not leak in.
Auto Trait Implementations§
impl<V> Freeze for Endpointer<V>where
V: Freeze,
impl<V> RefUnwindSafe for Endpointer<V>where
V: RefUnwindSafe,
impl<V> Send for Endpointer<V>where
V: Send,
impl<V> Sync for Endpointer<V>where
V: Sync,
impl<V> Unpin for Endpointer<V>where
V: Unpin,
impl<V> UnsafeUnpin for Endpointer<V>where
V: UnsafeUnpin,
impl<V> UnwindSafe for Endpointer<V>where
V: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more