@sam17896/ngx-speech-recognition
Version:
Angular 5+ speech recognition service (based on browser implementation such as Chrome).
2 lines • 14.9 kB
JavaScript
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("rxjs"),require("rxjs/operators"),require("@angular/core"),require("@angular/common")):"function"==typeof define&&define.amd?define("@sam17896/ngx-speech-recognition",["exports","rxjs","rxjs/operators","@angular/core","@angular/common"],n):n((e.sam17896=e.sam17896||{},e.sam17896["ngx-speech-recognition"]={}),e.rxjs,e.rxjs.operators,e.ng.core,e.ng.common)}(this,function(e,c,n,t,r){"use strict";window.webkitSpeechRecognition&&(window.SpeechRecognition=window.webkitSpeechRecognition),window.webkitSpeechGrammarList&&(window.SpeechGrammarList=window.webkitSpeechGrammarList);var o=new t.InjectionToken("speech-recognition.grammars"),i=new t.InjectionToken("speech-recognition.lang"),s=new t.InjectionToken("speech-recognition.continuous"),a=new t.InjectionToken("speech-recognition.interimResults"),u=new t.InjectionToken("speech-recognition.maxAlternatives"),l=new t.InjectionToken("speech-recognition.serviceURI"),d=new t.InjectionToken("speech-recognition.onaudiostart"),p=new t.InjectionToken("speech-recognition.onsoundstart"),h=new t.InjectionToken("speech-recognition.onspeechstart"),f=new t.InjectionToken("speech-recognition.onspeechend"),g=new t.InjectionToken("speech-recognition.onsoundend"),y=new t.InjectionToken("speech-recognition.onaudioend"),m=new t.InjectionToken("speech-recognition.onresult"),v=new t.InjectionToken("speech-recognition.onnomatch"),b=new t.InjectionToken("speech-recognition.onerror"),j=new t.InjectionToken("speech-recognition.onstart"),R=new t.InjectionToken("speech-recognition.onend"),I=function(e,n){return(I=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,n){e.__proto__=n}||function(e,n){for(var t in n)n.hasOwnProperty(t)&&(e[t]=n[t])})(e,n)};function H(e,n){function t(){this.constructor=e}I(e,n),e.prototype=null===n?Object.create(n):(t.prototype=n.prototype,new t)}function _(){for(var e=[],n=0;n<arguments.length;n++)e=e.concat(function(e,n){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var r,o,i=t.call(e),s=[];try{for(;(void 0===n||0<n--)&&!(r=i.next()).done;)s.push(r.value)}catch(a){o={error:a}}finally{try{r&&!r.done&&(t=i["return"])&&t.call(i)}finally{if(o)throw o.error}}return s}(arguments[n]));return e}var O=(Object.defineProperty(w.prototype,"grammars",{get:function(){return this._grammars},set:function(e){this._grammars=e,this._grammars!==undefined&&null!=this._grammars&&this.internal&&(this.internal.grammars=this._grammars)},enumerable:!0,configurable:!0}),Object.defineProperty(w.prototype,"lang",{get:function(){return this._lang},set:function(e){this._lang=e,this._lang!==undefined&&null!=this._lang&&this.internal&&(this.internal.lang=this._lang)},enumerable:!0,configurable:!0}),Object.defineProperty(w.prototype,"continuous",{get:function(){return this._continuous},set:function(e){this._continuous=e,this._continuous!==undefined&&null!=this._continuous&&this.internal&&(this.internal.continuous=this._continuous)},enumerable:!0,configurable:!0}),Object.defineProperty(w.prototype,"interimResults",{get:function(){return this._interimResults},set:function(e){this._interimResults=e,this._interimResults!==undefined&&null!=this._interimResults&&this.internal&&(this.internal.interimResults=this._interimResults)},enumerable:!0,configurable:!0}),Object.defineProperty(w.prototype,"maxAlternatives",{get:function(){return this._maxAlternatives},set:function(e){this._maxAlternatives=e,this._maxAlternatives!==undefined&&null!=this._maxAlternatives&&this.internal&&(this.internal.maxAlternatives=this._maxAlternatives)},enumerable:!0,configurable:!0}),Object.defineProperty(w.prototype,"serviceURI",{get:function(){return this._serviceURI},set:function(e){this._serviceURI=e,this._serviceURI!==undefined&&null!=this._serviceURI&&this.internal&&(this.internal.serviceURI=this._serviceURI)},enumerable:!0,configurable:!0}),w);function w(e,n,t,r,o,i){this._grammars=e,this._lang=n,this._continuous=t,this._interimResults=r,this._maxAlternatives=o,this._serviceURI=i,this.internal=new SpeechRecognition}var S,x,k=c.pipe((S="result",n.filter(function(e){return e.type===S})),n.map(function(e){return e.results})),V=(H(F,x=O),Object.defineProperty(F.prototype,"$",{get:function(){return this.proxy$},enumerable:!0,configurable:!0}),Object.defineProperty(F.prototype,"started$",{get:function(){return this._started$},enumerable:!0,configurable:!0}),F.prototype.initInternal=function(){var n=this,e=function(e){n.proxy$.next(e),n.ref.tick()};this.internal.onaudiostart=e,this.internal.onsoundstart=e,this.internal.onspeechstart=e,this.internal.onspeechend=e,this.internal.onsoundend=e,this.internal.onaudioend=e,this.internal.onresult=e,this.internal.onnomatch=e,this.internal.onerror=function(e){n.proxy$.error(e),n.ref.tick()},this.internal.onstart=e,this.internal.onend=e,this.grammars=this._grammars,this.lang=this._lang,this.continuous=this._continuous,this.interimResults=this._interimResults,this.maxAlternatives=this._maxAlternatives,this.serviceURI=this._serviceURI,this.proxy$.subscribe(function(e){switch(e.type){case"start":n._started$.next(!0);break;case"end":n._started$.next(!1)}})},F.prototype.listen=function(){var r=this;return new c.Observable(function(n){var t=r.proxy$.subscribe({next:function(e){n.next(e),e.type&&"end"===e.type&&(r.internal.stop(),n.complete(),t.unsubscribe())},error:function(e){return n.error(e)}});return r.internal.start(),function(){r.internal.abort(),t.unsubscribe()}})},F.decorators=[{type:t.Injectable}],F.ctorParameters=function(){return[{type:t.ApplicationRef},{type:undefined,decorators:[{type:t.Optional},{type:t.Inject,args:[o]}]},{type:String,decorators:[{type:t.Optional},{type:t.Inject,args:[i]}]},{type:Boolean,decorators:[{type:t.Optional},{type:t.Inject,args:[s]}]},{type:Boolean,decorators:[{type:t.Optional},{type:t.Inject,args:[a]}]},{type:Number,decorators:[{type:t.Optional},{type:t.Inject,args:[u]}]},{type:String,decorators:[{type:t.Optional},{type:t.Inject,args:[l]}]}]},F);function F(e,n,t,r,o,i,s){var a=x.call(this,n,t,r,o,i,s)||this;return a.ref=e,a.proxy$=new c.Subject,a._started$=new c.BehaviorSubject(!1),a.initInternal(),a}var P,A=(H(U,P=O),U.prototype.initHandlers=function(){var e=function(){};this.audiostartHandler||(this.audiostartHandler=e),this.soundstartHandler||(this.soundstartHandler=e),this.speechstartHandler||(this.speechstartHandler=e),this.speechendHandler||(this.speechendHandler=e),this.soundendHandler||(this.soundendHandler=e),this.audioendHandler||(this.audioendHandler=e),this.resultHandler||(this.resultHandler=e),this.nomatchHandler||(this.nomatchHandler=e),this.errorHandler||(this.errorHandler=e),this.startHandler||(this.startHandler=e),this.endHandler||(this.endHandler=e)},U.prototype.initInternal=function(){var n=this;this.grammars=this._grammars,this.lang=this._lang,this.continuous=this._continuous,this.interimResults=this._interimResults,this.maxAlternatives=this._maxAlternatives,this.serviceURI=this._serviceURI,this.internal.onaudiostart=function(e){n.audiostartHandler(e),n.ref.tick()},this.internal.onsoundstart=function(e){n.soundstartHandler(e),n.ref.tick()},this.internal.onspeechstart=function(e){n.speechstartHandler(e),n.ref.tick()},this.internal.onspeechend=function(e){n.speechendHandler(e),n.ref.tick()},this.internal.onsoundend=function(e){n.soundendHandler(e),n.ref.tick()},this.internal.onaudioend=function(e){n.audioendHandler(e),n.ref.tick()},this.internal.onresult=function(e){n.resultHandler(e),n.ref.tick()},this.internal.onnomatch=function(e){n.nomatchHandler(e),n.ref.tick()},this.internal.onerror=function(e){n.errorHandler(e),n.ref.tick()},this.internal.onstart=function(e){n.startHandler(e),n.ref.tick()},this.internal.onend=function(e){n.endHandler(e),n.ref.tick()}},Object.defineProperty(U.prototype,"onaudiostart",{set:function(e){this.audiostartHandler=e},enumerable:!0,configurable:!0}),Object.defineProperty(U.prototype,"onsoundstart",{set:function(e){this.soundstartHandler=e},enumerable:!0,configurable:!0}),Object.defineProperty(U.prototype,"onspeechstart",{set:function(e){this.speechstartHandler=e},enumerable:!0,configurable:!0}),Object.defineProperty(U.prototype,"onspeechend",{set:function(e){this.speechendHandler=e},enumerable:!0,configurable:!0}),Object.defineProperty(U.prototype,"onsoundend",{set:function(e){this.soundendHandler=e},enumerable:!0,configurable:!0}),Object.defineProperty(U.prototype,"onaudioend",{set:function(e){this.audioendHandler=e},enumerable:!0,configurable:!0}),Object.defineProperty(U.prototype,"onresult",{set:function(e){this.resultHandler=e},enumerable:!0,configurable:!0}),Object.defineProperty(U.prototype,"onnomatch",{set:function(e){this.nomatchHandler=e},enumerable:!0,configurable:!0}),Object.defineProperty(U.prototype,"onerror",{set:function(e){this.errorHandler=e},enumerable:!0,configurable:!0}),Object.defineProperty(U.prototype,"onstart",{set:function(e){this.startHandler=e},enumerable:!0,configurable:!0}),Object.defineProperty(U.prototype,"onend",{set:function(e){this.endHandler=e},enumerable:!0,configurable:!0}),U.prototype.start=function(){this.internal.start(),this.ref.tick()},U.prototype.stop=function(){this.internal.stop(),this.ref.tick()},U.prototype.abort=function(){this.internal.abort(),this.ref.tick()},U.decorators=[{type:t.Injectable}],U.ctorParameters=function(){return[{type:t.ApplicationRef},{type:undefined,decorators:[{type:t.Optional},{type:t.Inject,args:[o]}]},{type:String,decorators:[{type:t.Optional},{type:t.Inject,args:[i]}]},{type:Boolean,decorators:[{type:t.Optional},{type:t.Inject,args:[s]}]},{type:Boolean,decorators:[{type:t.Optional},{type:t.Inject,args:[a]}]},{type:Number,decorators:[{type:t.Optional},{type:t.Inject,args:[u]}]},{type:String,decorators:[{type:t.Optional},{type:t.Inject,args:[l]}]},{type:Function,decorators:[{type:t.Optional},{type:t.Inject,args:[d]}]},{type:Function,decorators:[{type:t.Optional},{type:t.Inject,args:[p]}]},{type:Function,decorators:[{type:t.Optional},{type:t.Inject,args:[h]}]},{type:Function,decorators:[{type:t.Optional},{type:t.Inject,args:[f]}]},{type:Function,decorators:[{type:t.Optional},{type:t.Inject,args:[g]}]},{type:Function,decorators:[{type:t.Optional},{type:t.Inject,args:[y]}]},{type:Function,decorators:[{type:t.Optional},{type:t.Inject,args:[m]}]},{type:Function,decorators:[{type:t.Optional},{type:t.Inject,args:[v]}]},{type:Function,decorators:[{type:t.Optional},{type:t.Inject,args:[b]}]},{type:Function,decorators:[{type:t.Optional},{type:t.Inject,args:[j]}]},{type:Function,decorators:[{type:t.Optional},{type:t.Inject,args:[R]}]}]},U);function U(e,n,t,r,o,i,s,a,c,u,l,d,p,h,f,g,y,m){var v=P.call(this,n,t,r,o,i,s)||this;return v.ref=e,v.audiostartHandler=a,v.soundstartHandler=c,v.speechstartHandler=u,v.speechendHandler=l,v.soundendHandler=d,v.audioendHandler=p,v.resultHandler=h,v.nomatchHandler=f,v.errorHandler=g,v.startHandler=y,v.endHandler=m,v.initHandlers(),v.initInternal(),v}var T=[{provide:s,useValue:!1},{provide:a,useValue:!1},{provide:u,useValue:1}],$=(M.forRoot=function(e){return{ngModule:M,providers:_(e.grammars!==undefined&&null!=e.grammars?[{useValue:e.grammars,provide:o}]:[],e.lang!==undefined&&null!=e.lang?[{useValue:e.lang,provide:i}]:[],e.continuous!==undefined&&null!=e.continuous?[{useValue:e.continuous,provide:s}]:[],e.interimResults!==undefined&&null!=e.interimResults?[{useValue:e.interimResults,provide:a}]:[],e.maxAlternatives!==undefined&&null!=e.maxAlternatives?[{useValue:e.maxAlternatives,provide:u}]:[],e.serviceURI!==undefined&&null!=e.serviceURI?[{useValue:e.serviceURI,provide:l}]:[],e.onaudiostart instanceof Function?[{useValue:e.onaudiostart,provide:d}]:[],e.onsoundstart instanceof Function?[{useValue:e.onsoundstart,provide:p}]:[],e.onspeechstart instanceof Function?[{useValue:e.onspeechstart,provide:h}]:[],e.onspeechend instanceof Function?[{useValue:e.onspeechend,provide:f}]:[],e.onsoundend instanceof Function?[{useValue:e.onsoundend,provide:g}]:[],e.onaudioend instanceof Function?[{useValue:e.onaudioend,provide:y}]:[],e.onresult instanceof Function?[{useValue:e.onresult,provide:m}]:[],e.onnomatch instanceof Function?[{useValue:e.onnomatch,provide:v}]:[],e.onerror instanceof Function?[{useValue:e.onerror,provide:b}]:[],e.onstart instanceof Function?[{useValue:e.onstart,provide:j}]:[],e.onend instanceof Function?[{useValue:e.onend,provide:R}]:[],[{useClass:A,provide:A},{useClass:V,provide:V}])}},M.withConfig=function(e){return{ngModule:M,providers:_(e.grammars!==undefined&&null!=e.grammars?[{useValue:e.grammars,provide:o}]:[],e.lang!==undefined&&null!=e.lang?[{useValue:e.lang,provide:i}]:[],e.continuous!==undefined&&null!=e.continuous?[{useValue:e.continuous,provide:s}]:[],e.interimResults!==undefined&&null!=e.interimResults?[{useValue:e.interimResults,provide:a}]:[],e.maxAlternatives!==undefined&&null!=e.maxAlternatives?[{useValue:e.maxAlternatives,provide:u}]:[],e.serviceURI!==undefined&&null!=e.serviceURI?[{useValue:e.serviceURI,provide:l}]:[],e.onaudiostart instanceof Function?[{useValue:e.onaudiostart,provide:d}]:[],e.onsoundstart instanceof Function?[{useValue:e.onsoundstart,provide:p}]:[],e.onspeechstart instanceof Function?[{useValue:e.onspeechstart,provide:h}]:[],e.onspeechend instanceof Function?[{useValue:e.onspeechend,provide:f}]:[],e.onsoundend instanceof Function?[{useValue:e.onsoundend,provide:g}]:[],e.onaudioend instanceof Function?[{useValue:e.onaudioend,provide:y}]:[],e.onresult instanceof Function?[{useValue:e.onresult,provide:m}]:[],e.onnomatch instanceof Function?[{useValue:e.onnomatch,provide:v}]:[],e.onerror instanceof Function?[{useValue:e.onerror,provide:b}]:[],e.onstart instanceof Function?[{useValue:e.onstart,provide:j}]:[],e.onend instanceof Function?[{useValue:e.onend,provide:R}]:[])}},M.decorators=[{type:t.NgModule,args:[{providers:[T]}]}],M.ctorParameters=function(){return[{type:String,decorators:[{type:t.Inject,args:[t.PLATFORM_ID]}]}]},M);function M(e){if(!1===r.isPlatformBrowser(e))throw new Error("SpeechRecognitionModule: it run on PlatformBrowser.")}e.SpeechRecognitionGrammars=o,e.SpeechRecognitionLang=i,e.SpeechRecognitionContinuous=s,e.SpeechRecognitionInterimResults=a,e.SpeechRecognitionMaxAlternatives=u,e.SpeechRecognitionServiceUri=l,e.SpeechRecognitionAudiostartHandler=d,e.SpeechRecognitionSoundstartHandler=p,e.SpeechRecognitionSpeechstartHandler=h,e.SpeechRecognitionSpeechendHandler=f,e.SpeechRecognitionSoundendHandler=g,e.SpeechRecognitionAudioendHandler=y,e.SpeechRecognitionResultHandler=m,e.SpeechRecognitionNomatchHandler=v,e.SpeechRecognitionErrorHandler=b,e.SpeechRecognitionStartHandler=j,e.SpeechRecognitionEndHandler=R,e.resultList=k,e.RxSpeechRecognitionService=V,e.SpeechRecognitionService=A,e.SPEECH_RECOGNITION_DEFAULT=T,e.SpeechRecognitionModule=$,e.ɵa=O,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=sam17896-ngx-speech-recognition.umd.min.js.map