Loading...
Loading...
Implement speech-to-text voice input in Blazor applications using Syncfusion SpeechToText component. ALWAYS use this when users need voice input, speech recognition, audio transcription, or implementing the SpeechToText component in Blazor. Trigger for Syncfusion.Blazor.Inputs, microphone input, voice-to-text conversion, language support, transcript binding, listening states, error handling, browser speech API, or any speech recognition requirements.
npx skill4agent add syncfusion/blazor-ui-components-skills syncfusion-blazor-speech-to-text@using Syncfusion.Blazor.Inputs
<div style="display: flex; flex-direction: column; gap: 20px; align-items: center; padding: 20px;">
<h3>Voice to Text Converter</h3>
<SfSpeechToText @bind-Transcript="@transcript"></SfSpeechToText>
<SfTextArea
RowCount="5"
ColumnCount="50"
@bind-Value="@transcript"
ResizeMode="Resize.None"
Placeholder="Transcribed text will appear here...">
</SfTextArea>
</div>
@code {
private string transcript = "";
}transcript<SfSpeechToText
AllowInterimResults="true"
@bind-Transcript="@transcript">
</SfSpeechToText>
<p>@transcript</p><select @onchange="@((ChangeEventArgs e) => selectedLanguage = e.Value.ToString())">
<option value="en-US">English</option>
<option value="fr-FR">French</option>
<option value="de-DE">German</option>
</select>
<SfSpeechToText
Language="@selectedLanguage"
@bind-Transcript="@transcript">
</SfSpeechToText>
@code {
private string selectedLanguage = "en-US";
private string transcript = "";
}<SfSpeechToText
ListeningState="@listeningState"
SpeechRecognitionStarted="@OnListeningStarted"
SpeechRecognitionStopped="@OnListeningStopped">
</SfSpeechToText>
<div style="margin-top: 15px;">
@if (listeningState == SpeechToTextState.Listening)
{
<span style="color: green;">🎤 Listening...</span>
}
else if (listeningState == SpeechToTextState.Stopped)
{
<span style="color: orange;">⏸ Stopped</span>
}
else
{
<span style="color: gray;">○ Ready to listen</span>
}
</div>
@code {
private SpeechToTextState listeningState = SpeechToTextState.Inactive;
private void OnListeningStarted(SpeechRecognitionStartedEventArgs args)
{
listeningState = args.State;
}
private void OnListeningStopped(SpeechRecognitionStoppedEventArgs args)
{
listeningState = args.State;
}
}<SfSpeechToText
SpeechRecognitionError="@OnSpeechError"
@bind-Transcript="@transcript">
</SfSpeechToText>
@if (!string.IsNullOrEmpty(errorMessage))
{
<div style="color: red; margin-top: 10px;">
⚠️ @errorMessage
</div>
}
@code {
private string transcript = "";
private string errorMessage = "";
private void OnSpeechError(SpeechRecognitionErrorEventArgs args)
{
errorMessage = args.Error switch
{
"no-speech" => "No speech detected. Please try again.",
"audio-capture" => "No microphone found. Check your device.",
"not-allowed" => "Microphone access denied. Check browser permissions.",
"network" => "Network error. Check your connection.",
_ => $"Error: {args.Error}"
};
}
}| Property | Type | Default | Purpose |
|---|---|---|---|
| string | "" | Two-way binding for transcribed text |
| string | "en-US" | Language code for speech recognition |
| SpeechToTextState | Inactive | Current state (Inactive, Listening, Stopped) |
| bool | true | Show interim results while speaking |
| bool | true | Display tooltip on hover |
| bool | false | Disable the component |
| Dictionary | - | Custom HTML attributes for button |