Text to Speech Module Reference

Table of contents


Introduction

The Text to Speech module contains an interface to the DOM or Cordova text-to-speech functions. WebApps will use the DOM, while native Cordova apps will use the Android or iOS native text-to-speech interface.


speech

Syntax

import {speech} from 'common/option/speech.js';

The speech object contains methods for the DOM text-to-speech functions.


speech methods

speech.isSpeak()

Syntax

speech.isSpeak()

Returns true if text-to-speech is available.

Return value

A Boolean.


speech.speak()

Syntax

speech.speak(text)
speech.speak(text, options)

Speaks the text on the device. The options argument can change the speech rate or supply a replacement dictionary. The method returns a Promise that resolves when the speech is completed. In a browser, speak() first cancels any speech in progress, so a new speak() interrupts the current speech rather than queueing behind it; the caller must wait for the Promise if it wants speech to run to completion. Any & left in the text after the dictionary is applied is replaced with and.

Parameters

Return value

A Promise that resolves when the speech is complete. In a browser, it rejects with the event's error value, except that speech that was canceled or interrupted resolves. On a native app, the Promise is the one returned by the Cordova TTS plugin, and it rejects with an Error if the plugin is not available.


speech.stop()

Syntax

speech.stop()

Stops any speech in progress. A pending speak() Promise for stopped speech resolves.

Return value

undefined.