pbakondy / cordova-plugin-speechrecognition

:microphone: Cordova Plugin for Speech Recognition
MIT License
196 stars 117 forks source link

How to use this plugin with Ionic 2? #12

Closed fahid-mahmood closed 7 years ago

fahid-mahmood commented 7 years ago

i am new to ionic i want to use your plugin with ionic 2 but unable to do so as there is no type definition included it tried many solutions e.g declare var SpeechRecognition:any; for calling the function but it's not recognizing them.

Really Sorry i know it's not the issue with your plugin but i am unable to find the solution i don't know where to ask so i am writing here.

Please help me i would be very thankful and please also update guide on your plugin too for ionic 2 it would help a lot of other peoples too thanks looking forward for your positive reply.

pbakondy commented 7 years ago

ionic 2 support is on the way. https://github.com/driftyco/ionic-native/pull/897

Until it arrives you should use plain JavaScript. TypeScrips allows to write native JS code without any type annotations.

fahid-mahmood commented 7 years ago

Thanks for quick reply great it would be great when this would be official ionic 2 plugin but i can't wait as i have to deliver the project so will stick with your other option. Thanks for the info i did not know about this as i am totally new to web programming i tried to write your sample code in typescript file test.ts

    window.plugins.speechRecognition.getSupportedLanguages(function(languages){
      // display the json array
      alert(languages);
    }, function(error){
      alert("Could not retrieve the supported languages : " + error);
    });

Error: Property 'plugins' does not exist on type 'Window'.

After that i tried the below code which is mentioned Stackoverflow

    window['plugins'].speechRecognition.getSupportedLanguages(function(languages){
      // display the json array
      alert(languages);
    }, function(error){
      alert("Could not retrieve the supported languages : " + error);
    });

Error: Cannot read property 'getSupportedLanguages' of undefined.

Please help me how i can call your functions from my ionic 2 typescript. I could have used other plugin but they are not written well like yours that's why i am doing so much struggle to make it work.

pbakondy commented 7 years ago

Why dont you try to apply my patch directly to your ionic-native package? Find the files under node_modules/ionic-native and add the changes.

On 28 Dec 2016 08:12, "mmajid" notifications@github.com wrote:

Thanks for quick reply great it would be great when this would be official ionic 2 plugin but i can't wait as i have to deliver the project so will stick with your other option. Thanks for the info i did not know about this as i am totally new to web programming i tried to write your sample code in typescript file test.ts

window.plugins.speechRecognition.getSupportedLanguages(function(languages){
  // display the json array
  alert(languages);
}, function(error){
  alert("Could not retrieve the supported languages : " + error);
});

Error: Property 'plugins' does not exist on type 'Window'.

After that i tried the below code which is mentioned Stackoverflow http://stackoverflow.com/questions/38000418/using-windows-plugins-with-ionic-2-typescript

window['plugins'].speechRecognition.getSupportedLanguages(function(languages){
  // display the json array
  alert(languages);
}, function(error){
  alert("Could not retrieve the supported languages : " + error);
});

Error: Cannot read property 'getSupportedLanguages' of undefined.

Please help me how i can call your functions from my ionic 2 typescript. I could have used other plugin but they are not written well like yours that's why i am doing so much struggle to make it work.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/pbakondy/cordova-plugin-speechrecognition/issues/12#issuecomment-269436621, or mute the thread https://github.com/notifications/unsubscribe-auth/AAej2QvKqnl7RO0bTzP-pPRAhiMuf5JRks5rMgv0gaJpZM4LWMqF .

fahid-mahmood commented 7 years ago

oh my bad thanks will let you know the result.

Truedison commented 7 years ago

declare var window:any after your imports

try to console.log(window.plugins), from there you can move forward

and you can use it there by then just done forget to check if the platform is ready and this can only be tested in a device.

fahid-mahmood commented 7 years ago

You are a life savior @Truedison i can't believe this was that easy. thanks alot

pbakondy commented 7 years ago

Check docs: https://github.com/pbakondy/cordova-plugin-speechrecognition#ionic-2-usage