Saturday 27 February 2016

Post 45: ionic Text to speech/text 2 speech/tts

Install plugin

cordova plugin add cordova-plugin-tts


In your index.html

<body ng-app="starter">
    <ion-pane ng-controller="AppCtrl">
      <ion-header-bar class="bar-stable">
        <h1 class="title">Cordova Text-to-Speech</h1>
      </ion-header-bar>
      <ion-content class="padding">
        <div class="list list-inset">
          <label class="item item-input">
            <i class="icon ion-speakerphone placeholder-icon"></i>
            <input type="text" placeholder="Let me speak..." ng-model="data.speechText">
          </label>
        </div>
        <button class="button button-full button-positive" ng-click="speakText()">
          Speak!
        </button>
      </ion-content>
    </ion-pane>
</body>


In your app.js:

angular.module('starter', ['ionic'])
 
.controller('AppCtrl', function($scope) {
  $scope.data = {
    speechText: ''
  };
  $scope.recognizedText = '';
 
  $scope.speakText = function() {
    TTS.speak({
           text: $scope.data.speechText,
           locale: 'en-GB',
           rate: 1.5
       }, function () {
           // Do Something after success
       }, function (reason) {
           // Handle the error case
       });
  };
 
});


For Android 6.0 you have to manually grant access to your microphone and storage.



Credits to: http://devgirl.org/2016/01/08/speaking-with-cordova/
Tweet