diff --git a/src/index.ts b/src/index.ts index abb0b4b954..acc5c881d8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -101,6 +101,7 @@ import { Shake } from './plugins/shake'; import { Sim } from './plugins/sim'; import { SMS } from './plugins/sms'; import { SocialSharing } from './plugins/socialsharing'; +import { SpeechRecognition } from './plugins/speech-recognition'; import { SpinnerDialog } from './plugins/spinnerdialog'; import { Splashscreen } from './plugins/splashscreen'; import { SQLite } from './plugins/sqlite'; @@ -220,6 +221,7 @@ export * from './plugins/shake'; export * from './plugins/sim'; export * from './plugins/sms'; export * from './plugins/socialsharing'; +export * from './plugins/speech-recognition'; export * from './plugins/spinnerdialog'; export * from './plugins/splashscreen'; export * from './plugins/sqlite'; @@ -342,6 +344,7 @@ window['IonicNative'] = { Splashscreen, SQLite, StatusBar, + SpeechRecognition, Stepcounter, StreamingMedia, Stripe, diff --git a/src/plugins/speech-recognition.ts b/src/plugins/speech-recognition.ts new file mode 100644 index 0000000000..5a3ef528c2 --- /dev/null +++ b/src/plugins/speech-recognition.ts @@ -0,0 +1,156 @@ +import { Plugin, Cordova } from './plugin'; +import { Observable } from 'rxjs/Observable'; + +export type SpeechRecognitionListeningOptions = SpeechRecognitionListeningOptionsIOS | SpeechRecognitionListeningOptionsAndroid; + +export interface SpeechRecognitionListeningOptionsIOS { + /** + * used language for recognition (default `"en-US"`) + */ + language?: string; + + /** + * umber of return matches (default `5`) + */ + matches?: number; + + /** + * Allow partial results to be returned (default `false`) + */ + showPartial?: boolean; +} + +export interface SpeechRecognitionListeningOptionsAndroid { + /** + * used language for recognition (default `"en-US"`) + */ + language?: string; + + /** + * number of return matches (maximum number of matches) + */ + matches?: number; + + /** + * displayed prompt of listener popup window + */ + prompt?: string; + + /** + * display listener popup window with prompt (default `true`) + */ + showPopup?: boolean; +} + +/** + * @name SpeechRecognition + * @description + * This plugin does speech recognition using cloud services + * + * @usage + * ``` + * import { SpeechRecognition } from 'ionic-native'; + * + * // Check feature available + * SpeechRecognition.isRecognitionAvailable() + * .then((available: boolean) => console.log(available)) + * + * // Start the recognition process + * SpeechRecognition.startListening(options) + * .subscribe( + * (matches: Array) => console.log(matches), + * (onerror) => console.log('error:', onerror) + * ) + * + * // Stop the recognition process (iOS only) + * SpeechRecognition.stopListening() + * + * // Get the list of supported languages + * SpeechRecognition.getSupportedLanguages() + * .then( + * (languages: Array) => console.log(languages), + * (error) => console.log(error) + * ) + * + * // Check permission + * SpeechRecognition.hasPermission() + * .then((hasPermission: boolean) => console.log(hasPermission)) + * + * // Request permissions + * SpeechRecognition.requestPermission() + * .then( + * () => console.log('Granted'), + * () => console.log('Denied') + * ) + * + * ``` + */ +@Plugin({ + pluginName: 'SpeechRecognition', + plugin: 'cordova-plugin-speechrecognition', + pluginRef: 'plugins.speechRecognition', + repo: 'https://github.com/pbakondy/cordova-plugin-speechrecognition', + platforms: ['Android', 'iOS'] +}) +export class SpeechRecognition { + + /** + * Check feature available + * @return {Promise} + */ + @Cordova() + static isRecognitionAvailable(): Promise { + return; + } + + /** + * Start the recognition process + * @return {Promise< Array >} list of recognized terms + */ + @Cordova({ + callbackOrder: 'reverse', + observable: true, + + }) + static startListening(options?: SpeechRecognitionListeningOptions): Observable> { + return; + } + + /** + * Stop the recognition process + */ + @Cordova({ + platforms: ['iOS'] + }) + static stopListening(): Promise { + return; + } + + /** + * Get the list of supported languages + * @return {Promise< Array >} list of languages + */ + @Cordova() + static getSupportedLanguages(): Promise> { + return; + } + + /** + * Check permission + * @return {Promise} has permission + */ + @Cordova() + static hasPermission(): Promise { + return; + } + + /** + * Request permissions + * @return {Promise} + */ + @Cordova() + static requestPermission(): Promise { + return; + } + +}