# .NET MAUI SpeechToTextButton Events

The .NET MAUI SpeechToTextButton emits a set of events that allow you to configure the component's behavior in response to speech recognition.

The .NET MAUI SpeechToTextButton exposes the following events:

* `SpeechRecognized`—Raised when the speech recognition is successful and the recognized text is available. The `SpeechRecognized` event handler receives two parameters:
  * The `sender` argument which is of type `object` but can be cast to `RadSpeechToTextButton`.
  * A `SpeechRecognizerSpeechRecognizedEventArgs` argument 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.
    * `FullTextConfidenceScore` property 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.

* `ErrorOccurred`—Raised when an error occurs during the speech recognition process. The `ErrorOccurred` event handler receives two parameters:
  * The `sender` argument which is of type `object` but can be cast to `RadSpeechToTextButton`.
  * A `SpeechRecognizerErrorOccurredEventArgs` argument 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 to `true` to prevent the default error handling behavior.

* `StateChanged`—Raised when the state of the speech recognizer changes. The `StateChanged` event handler receives two parameters:
  * The `sender` argument which is of type `object` but can be cast to `RadSpeechToTextButton`.
  * An `System.EventArgs`.

## Example

Here is an example using the `SpeechRecognized` and `ErrorOccurred` events:

**1.** Define the `SpeechToTextButton` in XAML:

```XAML
<Grid ColumnDefinitions="*, Auto"
	  RowDefinitions="Auto">
	<Editor x:Name="editor" 
			AutoSize="TextChanges" />
	<telerik:RadSpeechToTextButton x:Name="speechToTextButton"
								   ErrorOccurred="OnErrorOccurred"
								   SpeechRecognized="OnSpeechRecognized"
								   Grid.Column="1"
								   VerticalOptions="Start" />
</Grid>
```

**2.** Add the `telerik` namespace:

```XAML
xmlns:telerik="http://schemas.telerik.com/2022/xaml/maui"
```

**3.** Handle the `SpeechRecognized` event:

```C#
private void OnSpeechRecognized(object sender, Telerik.Maui.SpeechRecognizer.SpeechRecognizerSpeechRecognizedEventArgs e)
{
	this.editor.Text = e.FullText;
}
```

**4.** Handle the `ErrorOccurred` event:

```C#
private void OnErrorOccurred(object sender, Telerik.Maui.SpeechRecognizer.SpeechRecognizerErrorOccurredEventArgs e)
{
	e.Handled = true;
	var error = $"{e.Message}; {e.Exception}";
	Application.Current.Windows[0].Page.DisplayAlert("Error", error, "OK");
}
```

> For a runnable example with the SpeechToTextButton Events scenario, see the [SDKBrowser Demo Application](https://www.telerik.com/maui-ui/documentation/demos-and-sample-apps/sdkbrowser-app) and go to the **SpeechToTextButton > Features** category.

## See Also

* [Set Visual States](https://www.telerik.com/maui-ui/documentation/controls/speechtotextbutton/visual-states)
* [Custom Recognizer](https://www.telerik.com/maui-ui/documentation/controls/speechtotextbutton/custom-recognizer)
* [Execute Commands](https://www.telerik.com/maui-ui/documentation/controls/speechtotextbutton/commands)
* [Style the SpeechToTextButton](https://www.telerik.com/maui-ui/documentation/controls/speechtotextbutton/styling)
