Sunday, 14 February 2016

Post 44: Speech recognition

Install plugin:

cordova plugin add
Go into your index.html file and replace the body with this:

<body ng-app="starter">
    <ion-pane ng-controller="AppCtrl">        
      <ion-content class="padding">     
        <button class="button button-full button-positive" ng-click="record()">
        <div class="card">
          <div class="item item-text-wrap">
In your app.js replace the whole content with this:
angular.module('starter', ['ionic'])

.controller('AppCtrl', function($scope) {
  $scope.recognizedText = '';

  $scope.record = function() {
    var recognition = new SpeechRecognition();
    recognition.onresult = function(event) {
        if (event.results.length > 0) {
            $scope.recognizedText = event.results[0][0].transcript;

For Android 6.0 users, you have to grant the app permission to access the device's microphone.

Credits to: