Speech


How to use the speech classes of the bit Butil?

Usage
The speech features are split across two classes. Inject the ones you need and use them like this:
@inject Bit.Butil.SpeechSynthesis speechSynthesis
@inject Bit.Butil.SpeechRecognition speechRecognition

@code {
    await speechSynthesis.Speak("Hello from Butil!");
    await using var rec = await speechRecognition.Start(options, onResult: r => { /* ... */ });
}
SpeechSynthesis
The SpeechSynthesis class wraps the SpeechSynthesis API for text-to-speech.

GetVoices:
Returns the list of voices the platform makes available (MDN).



Speak:
Speaks the configured utterance with an optional voice, rate and pitch (MDN).



Pause / Resume / Cancel:
Pauses the current utterance, resumes a paused utterance, or cancels all pending utterances (MDN).



IsSpeaking:
Returns whether the engine is currently speaking (or paused) (MDN).

SpeechRecognition
The SpeechRecognition class wraps the SpeechRecognition API for speech-to-text (Chromium-based browsers).

Start:
Captures microphone input and reports interim and final transcripts through the onResult callback. The Continuous and InterimResults options control the stream, and onError / onEnd surface errors and completion. Returns an IAsyncDisposable handle that stops recognition when disposed (MDN).



Stop:
Stops the recognition session early. Disposing the handle returned by Start is equivalent (MDN).