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
impl SpeechState
Sourcepub fn new(_: &mut Context<'_, Self>) -> Self
pub fn new(_: &mut Context<'_, Self>) -> Self
Create a speech state with the default recognizer and input.
Sourcepub fn recognizer(self, recognizer: impl SpeechRecognizer) -> Self
pub fn recognizer(self, recognizer: impl SpeechRecognizer) -> Self
Recognize speech with recognizer instead of the system’s.
Sourcepub fn input(self, input: impl AudioInput) -> Self
pub fn input(self, input: impl AudioInput) -> Self
Capture audio from input instead of the microphone.
Sourcepub fn system_fallback(self, system_fallback: bool) -> Self
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.
Sourcepub fn stop_timeout(self, timeout: Duration) -> Self
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.
Sourcepub fn has_recognizer(&self) -> bool
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.
Sourcepub fn is_available(&self, cx: &App) -> bool
pub fn is_available(&self, cx: &App) -> bool
Whether a session can start now: Self::has_recognizer and the
recognizer reports itself available.
Sourcepub fn status(&self) -> SpeechStatus
pub fn status(&self) -> SpeechStatus
Where the state is in its session.
Sourcepub fn transcript(&self) -> SharedString
pub fn transcript(&self) -> SharedString
The transcript of the current or last session: every committed phrase followed by the current hypothesis.
Sourcepub fn levels(&self) -> impl ExactSizeIterator<Item = f32> + '_
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.
Sourcepub fn start(&mut self, cx: &mut Context<'_, Self>)
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.
Sourcepub fn stop(&mut self, cx: &mut Context<'_, Self>)
pub fn stop(&mut self, cx: &mut Context<'_, Self>)
Stop capturing and wait for the final result, which arrives as
SpeechEvent::Final.
Trait Implementations§
impl EventEmitter<SpeechEvent> for SpeechState
Auto Trait Implementations§
impl !Freeze for SpeechState
impl !RefUnwindSafe for SpeechState
impl !Send for SpeechState
impl !Sync for SpeechState
impl !UnwindSafe for SpeechState
impl Unpin for SpeechState
impl UnsafeUnpin for SpeechState
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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