macdonst/SpeechRecognitionPlugin

how to reference with ionic 2

ah3243 opened this issue · 2 comments

Hi are you able to write an example of how to implement this app with ionic 2 and typescript. I'm writting a short demo app but i'm not sure how to reference the plugin. I'm getting a '[ts] Cannot find name SpeechRecognition' Error.
Is this plugin compatible with ionic 2 yet?

Below is my main ts component

    import { Component } from '@angular/core';
    import { Platform } from 'ionic-angular';
    import { NavController } from 'ionic-angular';

    //declare var SpeechRecognition: any;
    declare var platform: any;

    @Component({
      selector: 'page-home',
      templateUrl: 'home.html'
    })
    export class HomePage {

      recognition: any;
      ready: boolean = false;

      constructor(public navCtrl: NavController, platform: Platform) {
        platform = platform;
        platform.ready().then(() => { 
          this.ready = true;
        });
      }

      SpeechToText(){
        if(this.ready){
          this.recognition = new SpeechRecognition(); 
          this.recognition.lang = 'en-US';
          this.recognition.onnomatch = (event => {
              console.log('No match found.');
          });
          this.recognition.onerror = (event => {
              console.log('Error happens.');
          });
          this.recognition.onresult = (event => {
              if (event.results.length > 0) {
                  console.log('Text: ', event.results[0][0].transcript);          
              }
          });     
          this.recognition.start();
        };
      }  
    }

thanks

hey @ah3243 i found this ionic guide about how to implement your own ionic-native wrapper. But i do not have enough time to try it myself
once you change your code in cloned ionic-native repo you need to run npm run build and then copy compiled code to your project's node_modules/ionic-native/src

@macdonst Any plans to support ionic 2?

Your example is working just remove the comment at
declare var SpeechRecognition: any;