Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to reference with ionic 2 #76

Open
ah3243 opened this issue Oct 23, 2016 · 2 comments
Open

how to reference with ionic 2 #76

ah3243 opened this issue Oct 23, 2016 · 2 comments

Comments

@ah3243
Copy link

ah3243 commented Oct 23, 2016

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

@okonon
Copy link

okonon commented Oct 26, 2016

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?

@yasseralsamman
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants