Angular SpeechToText Properties

A configuration object for the SpeechToText UI component.

accessKey

Specifies the shortcut key that sets focus on the UI component.

Type:

String

| undefined
Default Value: undefined

The value of this property will be passed to the accesskey attribute of the HTML element that underlies the UI component.

activeStateEnabled

Specifies whether the UI component changes its visual state as a result of user interaction.

Type:

Boolean

Default Value: false

The UI component switches to the active state when users press down the primary mouse button. When this property is set to true, the CSS rules for the active state apply. You can change these rules to customize the component.

Use this property when you display the component on a platform whose guidelines include the active state change for UI components.

customSpeechRecognizer

Allows you to implement custom speech recognition engines.

If you want to integrate a custom speech recognition engine, set customSpeechRecognizer.enabled to true. When you implement a custom speech recognizer, SpeechToText no longer does the following:

  • Listens to user speech.
  • Updates the component state. Set the SpeechToText state using the customSpeechRecognizer.isListening property.
  • Calls the onResult and onError handlers.

disabled

Specifies whether the UI component responds to user interaction.

Type:

Boolean

Default Value: false

elementAttr

Specifies the global attributes to be attached to the UI component's container element.

Type:

Object

Default Value: {}
HTML
TypeScript
  • <dx-speech-to-text ...
  • [elementAttr]="{ id: 'elementId', class: 'class-name' }">
  • </dx-speech-to-text>
  • import { DxSpeechToTextModule } from "devextreme-angular";
  • // ...
  • export class AppComponent {
  • // ...
  • }
  • @NgModule({
  • imports: [
  • // ...
  • DxSpeechToTextModule
  • ],
  • // ...
  • })

focusStateEnabled

Specifies whether the UI component can be focused using keyboard navigation.

Type:

Boolean

Default Value: false

height

Specifies the UI component's height.

Type:

Number

|

String

| undefined
Default Value: undefined

This property accepts a value of one of the following types:

  • Number
    The height in pixels.

  • String
    A CSS-accepted measurement of height. For example, "55px", "20vh", "80%", "inherit".

hint

Specifies text for a hint that appears when a user pauses on the UI component.

Type:

String

| undefined
Default Value: undefined

hoverStateEnabled

Specifies whether the UI component changes its state when a user pauses on it.

Type:

Boolean

Default Value: false

onContentReady

A function that is executed when the UI component is rendered or repainted.

Type:

Function

Function parameters:

Information about the event.

Object structure:
Name Type Description
element

HTMLElement | jQuery

The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery.

component SpeechToText

The UI component's instance.

element:

HTMLElement | jQuery

The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery.

component: SpeechToText

The UI component's instance.

Default Value: null

onDisposing

A function that is executed before the UI component is disposed of.

Type:

Function

Function parameters:

Information about the event.

Object structure:
Name Type Description
element

HTMLElement | jQuery

The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery.

component SpeechToText

The UI component's instance.

element:

HTMLElement | jQuery

The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery.

component: SpeechToText

The UI component's instance.

Default Value: null

onEnd

A function that is executed when the Web Speech API finishes transcription and SpeechToText switches to the initial component state.

Type:

Function

| undefined
Function parameters:

Information about the event.

Object structure:
Name Type Description
component SpeechToText

The UI component's instance.

element

HTMLElement | jQuery

The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery.

component: SpeechToText

The UI component's instance.

element:

HTMLElement | jQuery

The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery.

Default Value: undefined
NOTE
The component does not call this handler if you implement a custom speech recognition engine.

View Demo

onError

A function that is executed when the Web Speech API encounters an error.

Type:

Function

| undefined
Function parameters:

Information about the event.

Object structure:
Name Type Description
component SpeechToText

The UI component's instance.

element

HTMLElement | jQuery

The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery.

component: SpeechToText

The UI component's instance.

element:

HTMLElement | jQuery

The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery.

Default Value: undefined

The following code snippet demonstrates how to implement the notify() utility method to display a Web Speech API error in the onError handler:

app.component.html
app.component.ts
  • <dx-speech-to-text
  • (onError)="handleError($event)"
  • ></dx-speech-to-text>
  • import { DxSpeechToTextComponent, type DxSpeechToTextTypes } from 'devextreme-angular/ui/speech-to-text';
  • import notify from 'devextreme/ui/notify';
  •  
  • // ...
  • export class AppComponent {
  • handleError(e: DxSpeechToTextTypes.ErrorEvent) {
  • const speechEvent = e.event as SpeechRecognitionErrorEvent;
  • notify(`Web Speech API encountered an error: ${speechEvent.error}`);
  • }
  • }
NOTE
  • The component does not call this handler if you implement a custom speech recognition engine.

  • To add all SpeechRecognition types (including SpeechRecognitionErrorEvent) to your project:

    1. Install the @types/dom-speech-recognition package:

      Code
      • npm i -D @types/dom-speech-recognition
    2. Add "dom-speech-recognition" to the types array in your TypeScript configuration:

      tsconfig.app.json
      • {
      • "compilerOptions": {
      • "types": ["dom-speech-recognition"],
      • }
      • }

onInitialized

A function used in JavaScript frameworks to save the UI component instance.

Type:

Function

Function parameters:

Information about the event.

Object structure:
Name Type Description
element

HTMLElement | jQuery

The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery.

component SpeechToText

The UI component's instance.

element:

HTMLElement | jQuery

The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery.

component: SpeechToText

The UI component's instance.

Default Value: null
app.component.html
app.component.ts
  • <dx-speech-to-text
  • (onInitialized)="saveInstance($event)"
  • ></dx-speech-to-text>
  • import { Component } from "@angular/core";
  • import { type DxSpeechToTextTypes } from 'devextreme-angular/ui/speech-to-text';
  • import dxSpeechToText from "devextreme/ui/speech_to_text";
  •  
  • // ...
  • export class AppComponent {
  • speechToTextInstance: DxSpeechToTextTypes.InitializedEvent['component'] | null = null;
  •  
  • saveInstance(e: DxSpeechToTextTypes.InitializedEvent): void {
  • this.speechToTextInstance = e.component;
  • }
  • }
See Also
  • Get a UI component Instance in Angular

onOptionChanged

A function that is executed after a UI component property is changed.

Type:

Function

Function parameters:

Information about the event.

Object structure:
Name Type Description
value any

The modified property's new value.

previousValue any

The modified property's previous value.

name

String

The modified property. For nested properties, returns the root-level property.

fullName

String

The path to the modified property that includes all parent properties.

element

HTMLElement | jQuery

The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery.

component SpeechToText

The UI component's instance.

value: any

The modified property's new value.

previousValue: any

The modified property's previous value.

name:

String

The modified property. For nested properties, returns the root-level property.

fullName:

String

The path to the modified property that includes all parent properties.

element:

HTMLElement | jQuery

The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery.

component: SpeechToText

The UI component's instance.

Default Value: null

The following code snippet demonstrates how to subscribe to component property changes:

app.component.html
app.component.ts
app.module.ts
  • <dx-speech-to-text ...
  • (onOptionChanged)="handlePropertyChange($event)">
  • </dx-speech-to-text>
  • import { Component } from '@angular/core';
  • import { type DxSpeechToTextTypes } from 'devextreme-angular/ui/speech-to-text';
  •  
  • @Component({
  • selector: 'app-root',
  • templateUrl: './app.component.html',
  • styleUrls: ['./app.component.css']
  • })
  •  
  • export class AppComponent {
  • // ...
  • handlePropertyChange(e: DxSpeechToTextTypes.OptionChangedEvent) {
  • if(e.name === "changedProperty") {
  • // handle the property change here
  • }
  • }
  • }
  • import { BrowserModule } from '@angular/platform-browser';
  • import { NgModule } from '@angular/core';
  • import { AppComponent } from './app.component';
  • import { DxSpeechToTextModule } from 'devextreme-angular/ui/speech-to-text';
  •  
  • @NgModule({
  • declarations: [
  • AppComponent
  • ],
  • imports: [
  • BrowserModule,
  • DxSpeechToTextModule
  • ],
  • providers: [ ],
  • bootstrap: [AppComponent]
  • })
  •  
  • export class AppModule { }

onResult

A function that is executed when the Web Speech API returns a result.

Type:

Function

| undefined
Function parameters:

Information about the event.

Object structure:
Name Type Description
component SpeechToText

The UI component's instance.

element

HTMLElement | jQuery

The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery.

component: SpeechToText

The UI component's instance.

element:

HTMLElement | jQuery

The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery.

Default Value: undefined

The following code snippet demonstrates how to extract transcribed text in the onResult handler:

app.component.html
app.component.ts
  • <dx-speech-to-text
  • (onResult)="handleResult($event)"
  • ></dx-speech-to-text>
  • import { DxSpeechToTextComponent, type DxSpeechToTextTypes } from 'devextreme-angular/ui/speech-to-text';
  •  
  • // ...
  • export class AppComponent {
  • handleResult(e: DxSpeechToTextTypes.ResultEvent) {
  • const speechEvent = e.event as SpeechRecognitionEvent;
  • const resultText = Object.values(speechEvent.results)
  • .map((resultItem: unknown) => (resultItem as SpeechRecognitionResult)[0].transcript)
  • .join(" ");
  • }
  • }
NOTE
  • The component does not call this handler if you implement a custom speech recognition engine.

  • To add all SpeechRecognition types (including SpeechRecognitionEvent) to your project:

    1. Install the @types/dom-speech-recognition package:

      Code
      • npm i -D @types/dom-speech-recognition
    2. Add "dom-speech-recognition" to the types array in your TypeScript configuration:

      tsconfig.app.json
      • {
      • "compilerOptions": {
      • "types": ["dom-speech-recognition"],
      • }
      • }

View Demo

onStartClick

A function that is executed when the SpeechToText button is clicked or tapped in the initial component state.

Type:

Function

| undefined
Function parameters:

Information about the event.

Object structure:
Name Type Description
component SpeechToText

The UI component's instance.

element

HTMLElement | jQuery

The UI component's container.

event

Event (jQuery or EventObject)

The event that caused the function to execute. It is an EventObject or a jQuery.Event when you use jQuery.

component: SpeechToText

The UI component's instance.

element:

HTMLElement | jQuery

The UI component's container.

event:

Event (jQuery or EventObject)

The event that caused the function to execute. It is an EventObject or a jQuery.Event when you use jQuery.

Default Value: undefined

onStopClick

A function that is executed when the SpeechToText button is clicked or tapped in the "listening" component state.

Type:

Function

| undefined
Function parameters:

Information about the event.

Object structure:
Name Type Description
component SpeechToText

The UI component's instance.

element

HTMLElement | jQuery

The UI component's container.

event

Event (jQuery or EventObject)

The event that caused the function to execute. It is an EventObject or a jQuery.Event when you use jQuery.

component: SpeechToText

The UI component's instance.

element:

HTMLElement | jQuery

The UI component's container.

event:

Event (jQuery or EventObject)

The event that caused the function to execute. It is an EventObject or a jQuery.Event when you use jQuery.

Default Value: undefined

rtlEnabled

Switches the UI component to a right-to-left representation.

Type:

Boolean

Default Value: false

When this property is set to true, the UI component text flows from right to left, and the layout of elements is reversed. To switch the entire application/site to the right-to-left representation, assign true to the rtlEnabled field of the object passed to the DevExpress.config(config) method.

JavaScript
  • DevExpress.config({
  • rtlEnabled: true
  • });

DataGrid Demo Navigation UI Demo Editors Demo

speechRecognitionConfig

Configures the Web Speech API (SpeechRecognition properties).

This configuration object allows you to customize SpeechToText functionality.

startIcon

The SpeechToText button icon in the initial component state.

Type:

String

Default Value: 'micoutline'

This property accepts one of the following:

startText

The SpeechToText button text in the initial component state.

Type:

String

Default Value: ''

stopIcon

The SpeechToText button icon in the "listening" component state.

Type:

String

Default Value: 'stopfilled'

This property accepts one of the following:

stopText

The SpeechToText button text in the "listening" component state.

Type:

String

Default Value: ''

stylingMode

Specifies SpeechToText button styling.

Type:

ButtonStyle

Default Value: 'contained'

The following image demonstrates available SpeechToText types (arranged vertically) and styling modes (arranged horizontally):

A grid of DevExtreme SpeechToText components which demonstrate available SpeechToText types and styling modes.

tabIndex

Specifies the number of the element when the Tab key is used for navigating.

Type:

Number

Default Value: 0

The value of this property will be passed to the tabindex attribute of the HTML element that underlies the UI component.

type

Specifies the SpeechToText button type.

Type:

ButtonType

|

String

Default Value: 'normal'

The following image demonstrates available SpeechToText types (arranged vertically) and styling modes (arranged horizontally):

A grid of DevExtreme SpeechToText components which demonstrate available SpeechToText types and styling modes.

You can also create a SpeechToText type and define custom CSS rules:

app.component.html
app.component.css
  • <dx-speech-to-text ...
  • type="warning"
  • ></dx-speech-to-text>
  • .dx-button.dx-button-warning {
  • background-color: #ffc107;
  • }

visible

Specifies whether the UI component is visible.

Type:

Boolean

Default Value: true

width

Specifies the UI component's width.

Type:

Number

|

String

| undefined
Default Value: undefined

This property accepts a value of one of the following types:

  • Number
    The width in pixels.

  • String
    A CSS-accepted measurement of width. For example, "55px", "20vw", "80%", "auto", "inherit".