Methods in Blazor SpeechToText component
2 Apr 20251 minute to read
Start listening
You can use the StartListeningAsync public method to initiate the speech recognition and begins the conversion of the speech to text.
Stop listening
You can use the StopListeningAsync public method to stop capturing your speech and ends the speech recognition.
Below sample demonstrates the SpeechToText component configured with above methods.
@using Syncfusion.Blazor.Inputs
@using Syncfusion.Blazor.Buttons
<div class="speechtext-container">
<div class="actions">
<SfButton Content="Start Listening" OnClick="TriggerStartListening"></SfButton>
<SfButton Content="Stop Listening" OnClick="TriggerStopListening"></SfButton>
</div>
<SfSpeechToText @ref="@speechToText" @bind-Transcript="@transcript"> </SfSpeechToText>
<SfTextArea RowCount="5" ColumnCount="50" @bind-Value="@transcript" ResizeMode="Resize.None" Placeholder="Transcribed text will be shown here..."></SfTextArea>
</div>
@code {
SfSpeechToText speechToText;
string transcript = "";
private async Task TriggerStartListening()
{
await speechToText.StartListeningAsync();
}
private async Task TriggerStopListening()
{
await speechToText.StopListeningAsync();
}
}
<style>
.speechtext-container {
margin: 50px auto;
gap: 20px;
display: flex;
flex-direction: column;
align-items: center;
}
</style>