text: var e,t;e=this,t=function(e,t){var i=function(e,t,i,n){return new(i||(i=Promise))((function(o,s){function r(e){try{a(n.next(e))}catch(e){s(e)}}function c(e){try{a(n.throw(e))}catch(e){s(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,c)}a((n=n.apply(e,t||[])).next())}))};class n{constructor(){this.results=[],this.startTime=new Date,this.endTime=new Date}}class o{constructor(e,t){this.text=e,this.confidence=t}}class s{constructor(){this.RecognitionStatus="",this.Offset=0,this.Duration=0,this.DisplayText="",this.NBest=[]}}e.AzureSpeechRecognizer=class{constructor(e,i,n,o){this.speechSubscriptionKey=e,this.serviceRegion=i,this.speechConfig=t.SpeechConfig.fromSubscription(this.speechSubscriptionKey,this.serviceRegion),this.speechConfig.outputFormat=t.OutputFormat.Detailed,n&&(this.speechConfig.endpointId=n),this.audioConfig=o||t.AudioConfig.fromDefaultMicrophoneInput()}recognizeOnce(e){return e||(e=8),this.recognizer=new t.SpeechRecognizer(this.speechConfig,this.audioConfig),new Promise(((t,n)=>i(this,void 0,void 0,(function*(){var i;for(let i=0;i<e;i++){this.recoStart=new Date;try{const e=yield this.tryReco(this.recoStart);return void t(e)}catch(e){}i<e-1&&(yield new Promise((e=>setTimeout(e,250))))}let o=new Error("Failed to recognize speech");null===(i=this.onError)||void 0===i||i.call(this,o),n(o)}))))}tryReco(e){return new Promise(((i,n)=>{var o;this.recognizer.recognizing=(e,t)=>{var i;null===(i=this.onRecognizing)||void 0===i||i.call(this,t.result.text)},this.recognizer.recognized=(t,n)=>{var o;let s=this.convertResults(e,n.result);null===(o=this.onRecognized)||void 0===o||o.call(this,s),i(s)},this.recognizer.canceled=(e,i)=>{n(new Error(t.CancellationReason[i.reason]))},null===(o=this.recognizer)||void 0===o||o.recognizeOnceAsync()}))}startRecognizing(){this.recognizer=new t.SpeechRecognizer(this.speechConfig,this.audioConfig),this.recoStart=new Date,this.recognizer.recognizing=(e,t)=>{var i;null===(i=this.onRecognizing)||void 0===i||i.call(this,t.result.text)},this.recognizer.recognized=(e,t)=>{var i;let n=this.convertResults(this.recoStart,t.result);null===(i=this.onRecognized)||void 0===i||i.call(this,n)},this.recognizer.canceled=(e,i)=>{var n;let o=new Error(t.CancellationReason[i.reason]);this.onError?this.onError.call(this,o):null===(n=this.onRecognized)||void 0===n||n.call(this,null)},this.recognizer.startContinuousRecognitionAsync()}stopRecognizing(e){this.recognizer&&setTimeout((()=>{var e;null===(e=this.recognizer)||void 0===e||e.close(),this.recognizer=void 0}),e||0)}convertResults(e,i){if(i.reason===t.ResultReason.NoMatch)return null;let r=new n;r.startTime=this.addTicksToDate(e,i.offset),r.endTime=this.addTicksToDate(r.startTime,i.duration);let c=i.properties.getProperty(t.PropertyId.SpeechServiceResponse_JsonResult);const a=Object.assign(new s,JSON.parse(c)).NBest.map((e=>new o(e.Lexical,e.Confidence)));let h=Array.from(a);for(let e=0;e<a.length;e++){const t=a[e];if(t.text.search(/^([a-zA-Z]\s)+[a-zA-Z]$/)>=0){const e=t.text.replace(/\s/g,""),i=.9*t.confidence;h.push(new o(e,i))}else if(t.text.search(/^([a-zA-Z]\s)+[a-zA-Z]+$/)>=0){let e=t.text.match(/^(([a-zA-Z]\s)+)([a-zA-Z]+)$/);if(e&&4==e.length){const i=e[1].replace(/\s/g,""),n=e[3],s=.7*t.confidence;h.push(new o(i+" "+n,s))}}}return r.results=h.sort(((e,t)=>t.confidence-e.confidence)),r}addTicksToDate(e,t){let i=1e4*e.getTime()+621355968e9;return new Date((i+t-621355968e9)/1e4)}},Object.defineProperty(e,"__esModule",{value:!0})},"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("microsoft-cognitiveservices-speech-sdk")):"function"==typeof define&&define.amd?define(["exports","microsoft-cognitiveservices-speech-sdk"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).StpAS={},e.SpeechSDK);