Events in EJ2 React Speech To Text
10 Aug 20265 minutes to read
This section describes the events that are triggered when performing actions with the SpeechToText component. The following events are available:
| Name | Args | Description |
|---|---|---|
| created | - | Triggers when the SpeechToText component’s rendering is fully completed. |
| onStart | StartListeningEventArgs | Triggers when speech recognition begins. |
| onStop | StopListeningEventArgs | Triggers when speech recognition stops. |
| onError | ErrorEventArgs | Triggers when an error occurs during speech recognition or listening. For a list of possible errors, refer to the Error handling section. |
| transcriptChanged | TranscriptChangedEventArgs | Triggers when a transcription change occurs during speech recognition. |
The following example demonstrates how to configure the SpeechToText events.
// Import the SpeechToText.
import { SpeechToTextComponent } from '@syncfusion/ej2-react-inputs';
import * as React from 'react';
import * as ReactDom from 'react-dom';
// To render SpeechToText.
export default class App extends React.Component {
onTranscriptChanged = (args) => {
//your required action here
};
onErrorHandler = (args) => {
//your required action here
};
onListeningStart = (args) => {
//your required action here
};
onListeningStop = (args) => {
//your required action here
};
onCreated = () => {
//your required action here
};
render() {
return (
<div id='container'>
<SpeechToTextComponent created={this.onCreated.bind(this)} transcriptChanged={this.onTranscriptChanged.bind(this)} onStart={this.onListeningStart.bind(this)} onStop={this.onListeningStop.bind(this)} onError={this.onErrorHandler.bind(this)}></SpeechToTextComponent>
</div>
);
}
}
ReactDom.render(<App />,document.getElementById('element'));// Import the SpeechToText.
import { SpeechToTextComponent, TranscriptChangedEventArgs, ErrorEventArgs, StartListeningEventArgs, StopListeningEventArgs } from '@syncfusion/ej2-react-inputs';
import * as React from 'react';
import * as ReactDom from 'react-dom';
// To render SpeechToText.
function App() {
function onTranscriptChanged(args: TranscriptChangedEventArgs) {
//your required action here
};
function onErrorHandler(args: ErrorEventArgs) {
//your required action here
};
function onListeningStart(args: StartListeningEventArgs) {
//your required action here
};
function onListeningStop(args: StopListeningEventArgs) {
//your required action here
};
function onCreated() {
//your required action here
};
return (
<div id='container'>
<SpeechToTextComponent created={onCreated} transcriptChanged={onTranscriptChanged} onStart={onListeningStart} onStop={onListeningStop} onError={onErrorHandler}></SpeechToTextComponent>
</div>
);
}
export default App;
ReactDom.render(<App />,document.getElementById('element'));#container {
margin: 50px auto;
gap: 20px;
display: flex;
flex-direction: column;
align-items: center;
}
/* Represents the styles for loader */
#loader {
color: #008cff;
font-family: 'Helvetica Neue', 'calibiri';
font-size: 14px;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}