Loading...
Loading...
Implement the Syncfusion Angular SpeechToText component. Use this skill for real-time speech-to-text conversion with text transcripts, custom button appearance and tooltips, recognition event handling, multiple language support with localization and RTL, error handling, and security best practices for microphone access and data transmission.
npx skill4agent add syncfusion/angular-ui-components-skills syncfusion-angular-speech-to-textimport { Component, ViewChild } from '@angular/core';
import { SpeechToTextModule, TextAreaComponent, TextAreaModule, TranscriptChangedEventArgs } from '@syncfusion/ej2-angular-inputs';
@Component({
imports: [SpeechToTextModule, TextAreaModule],
standalone: true,
selector: 'app-root',
template: `
<div class="speechText-container">
<button ejs-speechtotext
(transcriptChanged)="onTranscriptChange($event)">
</button>
<ejs-textarea #outputTextarea
id="textareaInst"
value=""
rows="5"
cols="50"
resizeMode="None"
placeholder="Transcribed text will be shown here...">
</ejs-textarea>
</div>`
})
export class AppComponent {
@ViewChild('outputTextarea') outputTextarea!: TextAreaComponent;
onTranscriptChange(args: TranscriptChangedEventArgs): void {
this.outputTextarea.value = args.transcript;
}
}public buttonSettings: ButtonSettingsModel = {
content: 'Start Listening',
stopContent: 'Stop Listening',
iconCss: 'e-icons e-play',
stopIconCss: 'e-icons e-pause',
isPrimary: true
};
onListeningStart(args: StartListeningEventArgs): void {
console.log('Listening started');
}
onListeningStop(args: StopListeningEventArgs): void {
console.log('Listening stopped');
}L10n.load({
'de': {
"speech-to-text": {
"startAriaLabel": "Drücken Sie, um zu sprechen",
"stopAriaLabel": "Drücken Sie, um zu stoppen",
"noSpeechError": "Keine Sprache erkannt"
}
}
});@ViewChild('speechtotext') speechToText!: SpeechToTextComponent;
public startListening(): void {
this.speechToText.startListening();
}
public stopListening(): void {
this.speechToText.stopListening();
}onErrorHandler(args: ErrorEventArgs): void {
if (args.error === 'no-speech') {
console.log('No speech detected. Please try again.');
} else if (args.error === 'not-allowed') {
console.log('Microphone permission denied.');
}
}onListeningStart(args: StartListeningEventArgs): void {
// Cancel listening if conditions aren't met
if (!this.hasPermission || !navigator.onLine) {
args.cancel = true;
alert('Cannot start listening. Check permissions and connection.');
return;
}
// Track if user or system triggered the action
if (args.isInteracted) {
console.log('User clicked the button');
} else {
console.log('Started programmatically');
}
}onTranscriptChange(args: TranscriptChangedEventArgs): void {
if (args.isInterimResult) {
// Show interim results in real-time (lighter styling)
this.interimText = args.transcript;
} else {
// Process final results (save, send to API, etc.)
this.finalText = args.transcript;
this.saveTranscript(args.transcript);
}
}import { SpeechToTextState } from '@syncfusion/ej2-angular-inputs';
export class AppComponent {
public currentState: SpeechToTextState = SpeechToTextState.Inactive;
// Set component to listening state
startListening(): void {
this.currentState = SpeechToTextState.Listening;
}
// Set component to stopped state
stopListening(): void {
this.currentState = SpeechToTextState.Stopped;
}
// Reset to inactive state
resetState(): void {
this.currentState = SpeechToTextState.Inactive;
}
}import { OnDestroy } from '@angular/core';
export class AppComponent implements OnDestroy {
@ViewChild('speechtotext') speechToText!: SpeechToTextComponent;
ngOnDestroy(): void {
if (this.speechToText) {
this.speechToText.stopListening();
this.speechToText.destroy();
}
}
}| Prop | Type | Default | Purpose |
|---|---|---|---|
| ButtonSettingsModel | - | Configure button appearance and labels |
| TooltipSettingsModel | - | Customize tooltip content and position |
| string | | Set speech recognition language |
| boolean | | Enable real-time interim transcription |
| string | | Current recognized text (read-only) |
| SpeechToTextState | | Monitor listening status (Inactive, Listening, Stopped) |
| boolean | | Display tooltip on hover |
| boolean | | Disable component interaction |
| boolean | | Persist component state across page reloads |
| boolean | | Enable right-to-left text direction |
| string | - | Apply custom CSS classes |
| object | - | Set custom HTML attributes on button |
| string | | Set UI localization language |