Skip to main content

RecordingReader

Struct RecordingReader 

Source
pub struct RecordingReader { /* private fields */ }

Implementations§

Source§

impl RecordingReader

Source

pub fn from_samples(samples: &[f32]) -> Self

A finished recording of canonical 16 kHz mono samples, held in memory.

Source

pub fn from_samples_in( spool_dir: &Path, samples: &[f32], ) -> Result<Self, CaptureError>

Available on non-target_family=wasm only.

RecordingReader::from_samples, saved as a private WAV in spool_dir.

Source

pub fn from_pcm16_in( spool_dir: &Path, samples: &[i16], ) -> Result<Self, CaptureError>

Available on non-target_family=wasm only.

A finished recording of canonical samples already in 16-bit PCM, saved as a private WAV in spool_dir.

Source

pub fn fill_through(&mut self, position: u64) -> Result<bool, CaptureError>

Waits until the window reaches position, or until capture ends short of it. Returns whether it reached position.

Source

pub fn fill_available(&mut self) -> Result<(), CaptureError>

Available on non-target_family=wasm only.

Takes whatever audio has arrived, without waiting for more.

Source

pub fn fill(&mut self) -> Result<(), CaptureError>

Waits for capture to end.

Source

pub fn fork(&self) -> Self

A second reader of the same recording, with its own window and its own release floor: what one reader frees, the other still holds.

The recording keeps no history, so a fork opens where capture stands rather than at the beginning — ask RecordingReader::held_from where that was.

Every sample written from here on is copied into its queue until it drops, so a fork nobody reads grows without bound.

Source

pub fn fork_window(&mut self) -> Self

A fork that starts from this reader’s window, not where capture stands. It copies what this reader holds once it takes its queue.

Source

pub fn held_from(&self) -> u64

Stream position of the first sample this reader still holds.

Source

pub fn samples(&self) -> &[f32]

Samples this reader has collected and not yet released.

Source

pub fn held_to(&self) -> u64

Stream position just past the last sample held.

Source

pub fn span(&self, span: Range<u64>) -> &[f32]

The audio in span, clamped to the window. A span that ran off either edge yields what survives of it, which may be nothing.

Source

pub fn release_before(&mut self, position: u64)

Frees this reader’s audio before position; other readers keep their own copies.

Source

pub fn reached_end(&self) -> bool

Whether this reader has seen capture end. It learns that only when it reads past the audio it holds, so it can lag. RecordingReader::ended_at does not.

Source

pub fn finished_audio(&mut self) -> Result<&RecordedAudio, CaptureError>

The finished WAV. Waits for capture to end, and keeps none of the samples it waits through.

§Panics

On a fork: only the reader that opened the recording owns its audio.

Source

pub fn wait_for_end(&self, timeout: Duration) -> bool

Available on non-target_family=wasm only.

Waits up to timeout for capture to end, reading nothing. Returns whether it ended.

Source

pub fn waker(&self) -> RecordingWaker

Available on crate feature silero and non-target_family=wasm only.

Wakes this recording’s waiting readers without writing to it.

Source

pub fn ended_at(&self) -> Option<Instant>

Available on non-target_family=wasm only.

When capture ended. Unlike RecordingReader::reached_end, it does not wait for this reader to catch up.

Source

pub fn written(&self) -> u64

Stream position just past the last sample capture has written, whether or not this reader has taken it.

Source

pub fn duration(&self) -> Duration

How much audio capture has written, whether or not it has been read.

Source§

impl RecordingReader

Source

pub fn from_wav_file(path: impl AsRef<Path>) -> Result<Self, CaptureError>

Available on non-target_family=wasm only.

Opens a caller-owned canonical 16 kHz mono WAV as a finished recording.

The file is validated for format, not trust — trust policy is for artifacts a daemon loads on a user’s behalf, and this file is the caller’s own. The file is borrowed, never deleted, and read whole into memory: about 8 bytes per sample, near 460 MB per hour of audio.

Source

pub fn from_open_wav( file: File, path: impl AsRef<Path>, ) -> Result<Self, CaptureError>

Available on non-target_family=wasm only.

RecordingReader::from_wav_file over a file already open at path, so checks made on that descriptor cover what is read.

Trait Implementations§

Source§

impl Drop for RecordingReader

Retires this reader’s queue, so capture stops copying audio nobody will read into it.

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more