WinForms SpeechToTextButton Events
The RadSpeechToTextButton emits a set of events that allow you to configure the component's behavior in response to speech recognition.
The RadSpeechToTextButton exposes the following events:
-
SpeechRecognized—Raised when the speech recognition is successful and the recognized text is available. TheSpeechRecognizedevent handler receives two parameters:- The
senderargument which is of typeobjectbut can be cast toRadSpeechToTextButton. - A
SpeechRecognizerSpeechRecognizedEventArgsargument which has a reference to the:FullText(string) property that contains the current full text recognized from the speech input from the beginning of the current listening session.FullTextConfidenceScoreproperty that indicates the confidence level of the recognition. The value is between 0 and 1, indicating how confident the speech-to-text transcription is. If the value is -1, a confidence score could not be provided.
- The
-
ErrorOccurred—Raised when an error occurs during the speech recognition process. TheErrorOccurredevent handler receives two parameters:- The
senderargument which is of typeobjectbut can be cast toRadSpeechToTextButton. - A
SpeechRecognizerErrorOccurredEventArgsargument which has a reference to the:Message(string) property that contains the error message describing the issue that occurred during speech recognition.Exception(System.Exception) property that contains the exception associated with the speech recognizer error, if any.Handled(bool) property that determines whether the error has been handled. Set this totrueto prevent the default error handling behavior.
- The
-
StateChanged—Raised when the state of the speech recognizer changes. TheStateChangedevent handler receives two parameters:- The
senderargument which is of typeobjectbut can be cast toRadSpeechToTextButton. - An
System.EventArgs
- The
-
CalloutOpening—Occurs before the callout tooltip is opened, allowing customization or cancellation.- The
senderargument which is of typeobjectbut can be cast toRadSpeechToTextButton. - A
SpeechToTextTooltipOpeningEventArgsargument which has a reference to the:State(SpeechRecognizerState) property that indicates the current state of the speech recognizer (e.g.,Ready,Listening).Callout(RadCallout) property that provides access to the callout tooltip control, allowing you to customize its appearance and behavior.ToolTipText(string) property that gets or sets the text displayed in the tooltip. Modify this property to customize the tooltip message.Cancel(bool) property that determines whether the tooltip opening should be cancelled. Set this totrueto prevent the tooltip from being displayed.
- The
Examle: Handling Speech Recognition Errors
To handle errors related to the speech recognition service, use the ErrorOccurred event. The SpeechRecognizerErrorOccurredEventArgs provide information about the error message via the Message and Exception properties.
Using ErrorOccurred event handler
private void radSpeechToTextButton1_ErrorOccurred(object sender, SpeechRecognizerErrorOccurredEventArgs e)
{
e.Handled = true;
string errorMessage = e.Message;
Exception exception = e.Exception;
RadMessageBox.Show("Error: " + errorMessage, "Speech Recognition Error", MessageBoxButtons.OK, RadMessageIcon.Error);
}