Text to speech

The text-to-speech plugin does what it says, it synthesizes text to voice. The plugin uses AVSpeechSynthesizer on iOS and the android.speech.tts.TextToSpeech package on Android. Let's get started with installing the cordova plugin and respective npm package:

    $ ionic cordova:plugin add cordova-plugin-tts$ npm install @ionic-native/text-to-speech --save

We have used it in our application to speak out a push notification message, whenever a push message is sent from the server:

// src/app/app.component.tsimport { TextToSpeech } from '@ionic-native/text-to-    speech';constructor(private tts: TextToSpeech) { }push.on('notification', function(data) { TextToSpeechthis.tts.speak({text: data.message,   locale: 'en-GB', rate: 0.75}) ...

Get Hybrid Mobile Development with Ionic now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.