Skip to main content

SpeechState

Struct SpeechState 

Source
pub struct SpeechState { /* private fields */ }
Expand description

The state of a speech input: captures audio from an AudioInput, feeds it to a SpeechRecognizer and tracks the transcript.

Render it with SpeechButton and SpeechWaveform, and subscribe to SpeechEvent to receive the text.

The recognizer is, in order: the one passed to Self::recognizer; else the platform’s SystemRecognizer, unless Self::system_fallback turned it off; else none, and the state is not available. The input defaults to the Microphone. Both defaults need the speech feature.

Implementations§

Source§

impl SpeechState

Source

pub fn new(_: &mut Context<'_, Self>) -> Self

Create a speech state with the default recognizer and input.

Source

pub fn recognizer(self, recognizer: impl SpeechRecognizer) -> Self

Recognize speech with recognizer instead of the system’s.

Source

pub fn input(self, input: impl AudioInput) -> Self

Capture audio from input instead of the microphone.

Source

pub fn system_fallback(self, system_fallback: bool) -> Self

Whether to fall back to the platform’s recognizer when no Self::recognizer is set, default true.

On Windows the system recognizer dictates through Microsoft’s online service; turn this off when audio must not leave the application.

Source

pub fn stop_timeout(self, timeout: Duration) -> Self

Set how long Self::stop waits for the recognizer’s final result before ending the session with the transcript so far, default 3 seconds.

Source

pub fn has_recognizer(&self) -> bool

Whether a recognizer and an input are configured, so that speech input can work on this platform at all.

Source

pub fn is_available(&self, cx: &App) -> bool

Whether a session can start now: Self::has_recognizer and the recognizer reports itself available.

Source

pub fn status(&self) -> SpeechStatus

Where the state is in its session.

Source

pub fn transcript(&self) -> SharedString

The transcript of the current or last session: every committed phrase followed by the current hypothesis.

Source

pub fn levels(&self) -> impl ExactSizeIterator<Item = f32> + '_

Recent input levels in 0.0..=1.0, oldest first, one per 80 ms of audio. Peaks rise at once and fall back smoothly; background noise reads as 0.0.

Source

pub fn start(&mut self, cx: &mut Context<'_, Self>)

Start a session. Does nothing while one is running.

When the recognizer or the input fails to start, emits SpeechEvent::Error and stays idle.

Source

pub fn stop(&mut self, cx: &mut Context<'_, Self>)

Stop capturing and wait for the final result, which arrives as SpeechEvent::Final.

Source

pub fn cancel(&mut self, cx: &mut Context<'_, Self>)

End the session at once and discard its transcript.

Source

pub fn toggle(&mut self, cx: &mut Context<'_, Self>)

Start a session when idle, otherwise stop the running one.

Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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