Home » Android » android – Speech recognition using ionic framework

android – Speech recognition using ionic framework

Posted by: admin June 15, 2020 Leave a comment

Questions:

I am looking for a way to do speech recognition using ionic framework . I want to run an app in both ios and android device.
Currently i am providing a web view in both ios and android and have a common code base . I want to include speech recognition feature to it and fetch the output of speech .

How to&Answers:

It looks like you have at least a couple options if you search around for “cordova speech recognition” on Google and if you look at the plugin repo at Apache’s Cordova site.

Here’s two quick ones I found.

The key here is that Ionic Framework is built on Cordova, so really you want a Cordova plugin for speech recognition.

Answer:

I was stuck at the same point. Then I found a url where I got a solution. As per as url they followed a cordova plugin. So you need to follow these steps:

1 – add Cordova plugin

cordova plugin add https://github.com/macdonst/SpeechRecognitionPlugin

2 – add TTS plugin

cordova plugin add cordova-plugin-tts

3 – implementation of plugin code

app.controller('AppCtrl', function($scope) {
  $scope.data = {
    speechText: ''
  };
  $scope.recognizedText = '';

  $scope.speakText = function() {
    window.TTS.speak({
           text: $scope.data.speechText,
           locale: 'en-GB',
           rate: 0.7
       }, function () {
           // Do Something after success
       }, function (reason) {
           // Handle the error case
        alert(reason+"");
       });
  };

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

Enjoy your code time:)

Answer:

You can use ng-speech-recognition AngularJS directive, it is working with ionic Framework:

ng-speech-recognition