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.
speechimport {speech} from 'common/option/speech.js';
The speech object contains methods for the DOM text-to-speech functions.
speech methodsspeech.isSpeak()speech.isSpeak()
Returns true if text-to-speech is available.
A Boolean.
speech.speak()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.
textoptions[pattern, replacement] entries, each applied to the text in order with String.replace(), to change the pronunciation of words and abbreviations.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()speech.stop()
Stops any speech in progress. A pending speak() Promise for stopped speech resolves.
undefined.