Appearance in EJ2 React Speech To Text
10 Aug 202620 minutes to read
Customizing the button
You can use the buttonSettings property to customize the appearance of the start and stop buttons in the speech to text conversion.
Setting start content
You can use the content property to define text content for the listening start state in the SpeechToText button.
Setting stop content
You can use the stopContent property to define text content for the listening stop state in the SpeechToText button.
Setting iconcss
You can use the iconCss property to apply a CSS class to customize the icon appearance for the listening start state.
Setting stop iconcss
You can use the stopIconCss property to apply a CSS class to customize the icon appearance for the listening stop state.
Positioning the button icon
The iconPosition property controls the icon’s placement, allowing it to be displayed on the top, bottom, left, or right side of the button’s text.
Configuring the primary button
The isPrimary property configures the button’s appearance to indicate a primary action. Setting this to true makes the button more prominent. This is a convenient alternative to manually adding the e-primary style via the cssClass property.
The following code sample demonstrates how to configure these button properties.
// Import the SpeechToText.
import { SpeechToTextComponent, TextAreaComponent } 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 {
textareaObj;
onTranscriptChanged = (args) => {
this.textareaObj.value = args.transcript;
};
buttonSettings = {
content: 'Start',
stopContent: 'Stop',
iconCss: 'e-icons e-play',
stopIconCss: 'e-icons e-pause',
iconPosition: 'Right',
isPrimary: true
}
render() {
return (
<div id='container'>
<SpeechToTextComponent transcriptChanged={this.onTranscriptChanged.bind(this)} buttonSettings={this.buttonSettings.bind(this)}></SpeechToTextComponent>
<TextAreaComponent
id="textareaInst"
ref={(textarea) => {this.textareaObj = textarea} }
resizeMode="None"
rows={5}
cols={50}
value=""
placeholder="Transcribed text will be shown here..."
/>
</div>
);
}
}
ReactDom.render(<App />,document.getElementById('element'));// Import the SpeechToText.
import { SpeechToTextComponent, TextAreaComponent, TranscriptChangedEventArgs, ButtonSettingsModel } from '@syncfusion/ej2-react-inputs';
import * as React from 'react';
import * as ReactDom from 'react-dom';
// To render SpeechToText.
function App() {
let textareaObj: TextAreaComponent;
function onTranscriptChanged(args: TranscriptChangedEventArgs) {
textareaObj.value = args.transcript;
}
const buttonSettings: ButtonSettingsModel = {
content: 'Start',
stopContent: 'Stop',
iconCss: 'e-icons e-play',
stopIconCss: 'e-icons e-pause',
iconPosition: 'Right',
isPrimary: true
}
return (
<div id='container'>
<SpeechToTextComponent transcriptChanged={onTranscriptChanged} buttonSettings={buttonSettings}></SpeechToTextComponent>
<TextAreaComponent
id="textareaInst"
ref={textarea => textareaObj = textarea }
resizeMode="None"
rows={5}
cols={50}
value=""
placeholder="Transcribed text will be shown here..."
/>
</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%;
}Customizing the Tooltip Display
The tooltipSettings property allows customization of the tooltip’s content and position.
Setting start content
You can use the content property to customize the content to be displayed in the tooltip when the speech recognition begins.
Setting stop content
You can use the stopContent property to customize the stop button tooltip text which is displayed on-hover.
Positioning the tooltip
The position property determines the placement of the tooltip relative to the button.
The following example shows how to configure the tooltip settings.
// Import the SpeechToText.
import { SpeechToTextComponent, TextAreaComponent } 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 {
textareaObj;
onTranscriptChanged = (args) => {
textareaObj.current.value = args.transcript;
};
tooltipSettings = {
position: 'BottomRight',
content: 'Click the button to start recognition',
stopContent: 'Click the button to stop recognition'
}
render() {
return (
<div id='container'>
<SpeechToTextComponent transcriptChanged={this.onTranscriptChanged.bind(this)} tooltipSettings={this.tooltipSettings.bind(this)}></SpeechToTextComponent>
<TextAreaComponent
id="textareaInst"
ref={(textarea) => {this.textareaObj = textarea} }
resizeMode="None"
rows={5}
cols={50}
value=""
placeholder="Transcribed text will be shown here..."
/>
</div>
);
}
}
ReactDom.render(<App />,document.getElementById('element'));// Import the SpeechToText.
import { SpeechToTextComponent, TextAreaComponent, TranscriptChangedEventArgs, TooltipSettingsModel } from '@syncfusion/ej2-react-inputs';
import * as React from 'react';
import * as ReactDom from 'react-dom';
// To render SpeechToText.
function App() {
let textareaObj: TextAreaComponent;
function onTranscriptChanged(args: TranscriptChangedEventArgs) {
textareaObj.value = args.transcript;
}
const tooltipSettings: TooltipSettingsModel = {
position: 'BottomRight',
content: 'Click the button to start recognition',
stopContent: 'Click the button to stop recognition'
}
return (
<div id='container'>
<SpeechToTextComponent transcriptChanged={onTranscriptChanged} tooltipSettings={tooltipSettings}></SpeechToTextComponent>
<TextAreaComponent
id="textareaInst"
ref={(textarea) => {textareaObj = textarea} }
resizeMode="None"
rows={5}
cols={50}
value=""
placeholder="Transcribed text will be shown here..."
/>
</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%;
}Applying Custom Styles with cssClass
The cssClass property provides a way to apply custom styling to the Speech-to-Text component. This property can be used to add custom user-defined classes or apply predefined styles. You can customize by adding the cssClass property with the below defined class.
e-primary |
Represents a primary action. |
e-outline |
Renders the button with an outline style. |
e-info |
Indicates an informative action. |
e-success |
Indicates a positive action. |
e-warning |
Warns the user of a potential issue. |
e-danger |
Indicates a destructive or negative action. |
Setting cssclass
You can use the cssClass property to customize the appearance of the SpeechToText component.
// Import the SpeechToText.
import { SpeechToTextComponent, TextAreaComponent } 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 {
textareaObj;
onTranscriptChanged = (args) => {
this.textareaObj.value = args.transcript;
};
render() {
return (
<div className='speechText-container'>
<SpeechToTextComponent transcriptChanged={this.onTranscriptChanged.bind(this)} cssClass="customClass"></SpeechToTextComponent>
<TextAreaComponent
id="textareaInst"
ref={(textarea) => {this.textareaObj = textarea} }
resizeMode="None"
rows={5}
cols={50}
value=""
placeholder="Transcribed text will be shown here..."
/>
</div>
);
}
}
ReactDom.render(<App />,document.getElementById('element'));// Import the SpeechToText.
import { SpeechToTextComponent, TextAreaComponent, TranscriptChangedEventArgs } from '@syncfusion/ej2-react-inputs';
import * as React from 'react';
import * as ReactDom from 'react-dom';
// To render SpeechToText.
function App() {
let textareaObj: TextAreaComponent;
function onTranscriptChanged(args: TranscriptChangedEventArgs) {
textareaObj.value = args.transcript;
}
return (
<div className='speechText-container'>
<SpeechToTextComponent transcriptChanged={onTranscriptChanged} cssClass="customClass"></SpeechToTextComponent>
<TextAreaComponent
id="textareaInst"
ref={(textarea) => {textareaObj = textarea} }
resizeMode="None"
rows={5}
cols={50}
value=""
placeholder="Transcribed text will be shown here..."
/>
</div>
);
}
export default App;
ReactDom.render(<App />,document.getElementById('element'));/* 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%;
}
/* Represents the styles for the custom class added */
.speechText-container {
margin: 50px auto;
gap: 20px;
display: flex;
flex-direction: column;
align-items: center;
}
.speechText-container .e-speech-to-text.customClass {
background-color: #ff6347;
color: #fff;
border-radius: 5px;
}
.speechText-container .e-speech-to-text.customClass:hover,
.speechText-container .e-speech-to-text.customClass:focus {
background-color: #ff4500;
}