dd641961a7b769901cfb4d7b97b0c3ac9cdc43a7a428941e38db3d86f052fb12.json 18 KB

1
  1. {"ast":null,"code":"\"use strict\";\n\n// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT license.\nvar _asyncToGenerator = require(\"F:/workspace/202226701027/huinongbao-app/node_modules/@babel/runtime/helpers/asyncToGenerator.js\").default;\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.Recognizer = void 0;\nconst Exports_js_1 = require(\"../common.speech/Exports.js\");\nconst Exports_js_2 = require(\"../common/Exports.js\");\nconst Contracts_js_1 = require(\"./Contracts.js\");\nconst Exports_js_3 = require(\"./Exports.js\");\n/**\n * Defines the base class Recognizer which mainly contains common event handlers.\n * @class Recognizer\n */\nclass Recognizer {\n /**\n * Creates and initializes an instance of a Recognizer\n * @constructor\n * @param {AudioConfig} audioInput - An optional audio input stream associated with the recognizer\n * @param {PropertyCollection} properties - A set of properties to set on the recognizer\n * @param {IConnectionFactory} connectionFactory - The factory class used to create a custom IConnection for the recognizer\n */\n constructor(audioConfig, properties, connectionFactory) {\n this.audioConfig = audioConfig !== undefined ? audioConfig : Exports_js_3.AudioConfig.fromDefaultMicrophoneInput();\n this.privDisposed = false;\n this.privProperties = properties.clone();\n this.privConnectionFactory = connectionFactory;\n this.implCommonRecognizerSetup();\n }\n /**\n * Dispose of associated resources.\n * @member Recognizer.prototype.close\n * @function\n * @public\n */\n close(cb, errorCb) {\n Contracts_js_1.Contracts.throwIfDisposed(this.privDisposed);\n Exports_js_2.marshalPromiseToCallbacks(this.dispose(true), cb, errorCb);\n }\n /**\n * @Internal\n * Internal data member to support fromRecognizer* pattern methods on other classes.\n * Do not use externally, object returned will change without warning or notice.\n */\n get internalData() {\n return this.privReco;\n }\n /**\n * This method performs cleanup of resources.\n * The Boolean parameter disposing indicates whether the method is called\n * from Dispose (if disposing is true) or from the finalizer (if disposing is false).\n * Derived classes should override this method to dispose resource if needed.\n * @member Recognizer.prototype.dispose\n * @function\n * @public\n * @param {boolean} disposing - Flag to request disposal.\n */\n dispose(disposing) {\n var _this = this;\n return _asyncToGenerator(function* () {\n if (_this.privDisposed) {\n return;\n }\n _this.privDisposed = true;\n if (disposing) {\n if (_this.privReco) {\n yield _this.privReco.audioSource.turnOff();\n yield _this.privReco.dispose();\n }\n }\n })();\n }\n /**\n * This method returns the current state of the telemetry setting.\n * @member Recognizer.prototype.telemetryEnabled\n * @function\n * @public\n * @returns true if the telemetry is enabled, false otherwise.\n */\n static get telemetryEnabled() {\n return Exports_js_1.ServiceRecognizerBase.telemetryDataEnabled;\n }\n /**\n * This method globally enables or disables telemetry.\n * @member Recognizer.prototype.enableTelemetry\n * @function\n * @public\n * @param enabled - Global setting for telemetry collection.\n * If set to true, telemetry information like microphone errors,\n * recognition errors are collected and sent to Microsoft.\n * If set to false, no telemetry is sent to Microsoft.\n */\n static enableTelemetry(enabled) {\n Exports_js_1.ServiceRecognizerBase.telemetryDataEnabled = enabled;\n }\n // Does the generic recognizer setup that is common across all recognizer types.\n implCommonRecognizerSetup() {\n let osPlatform = typeof window !== \"undefined\" ? \"Browser\" : \"Node\";\n let osName = \"unknown\";\n let osVersion = \"unknown\";\n if (typeof navigator !== \"undefined\") {\n osPlatform = osPlatform + \"/\" + navigator.platform;\n osName = navigator.userAgent;\n osVersion = navigator.appVersion;\n }\n const recognizerConfig = this.createRecognizerConfig(new Exports_js_1.SpeechServiceConfig(new Exports_js_1.Context(new Exports_js_1.OS(osPlatform, osName, osVersion))));\n this.privReco = this.createServiceRecognizer(Recognizer.getAuthFromProperties(this.privProperties), this.privConnectionFactory, this.audioConfig, recognizerConfig);\n }\n recognizeOnceAsyncImpl(recognitionMode) {\n var _this2 = this;\n return _asyncToGenerator(function* () {\n Contracts_js_1.Contracts.throwIfDisposed(_this2.privDisposed);\n const ret = new Exports_js_2.Deferred();\n yield _this2.implRecognizerStop();\n yield _this2.privReco.recognize(recognitionMode, ret.resolve, ret.reject);\n const result = yield ret.promise;\n yield _this2.implRecognizerStop();\n return result;\n })();\n }\n startContinuousRecognitionAsyncImpl(recognitionMode) {\n var _this3 = this;\n return _asyncToGenerator(function* () {\n Contracts_js_1.Contracts.throwIfDisposed(_this3.privDisposed);\n yield _this3.implRecognizerStop();\n yield _this3.privReco.recognize(recognitionMode, undefined, undefined);\n })();\n }\n stopContinuousRecognitionAsyncImpl() {\n var _this4 = this;\n return _asyncToGenerator(function* () {\n Contracts_js_1.Contracts.throwIfDisposed(_this4.privDisposed);\n yield _this4.implRecognizerStop();\n })();\n }\n implRecognizerStop() {\n var _this5 = this;\n return _asyncToGenerator(function* () {\n if (_this5.privReco) {\n yield _this5.privReco.stopRecognizing();\n }\n return;\n })();\n }\n static getAuthFromProperties(properties) {\n const subscriptionKey = properties.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_Key, undefined);\n const authentication = subscriptionKey && subscriptionKey !== \"\" ? new Exports_js_1.CognitiveSubscriptionKeyAuthentication(subscriptionKey) : new Exports_js_1.CognitiveTokenAuthentication(() => {\n const authorizationToken = properties.getProperty(Exports_js_3.PropertyId.SpeechServiceAuthorization_Token, undefined);\n return Promise.resolve(authorizationToken);\n }, () => {\n const authorizationToken = properties.getProperty(Exports_js_3.PropertyId.SpeechServiceAuthorization_Token, undefined);\n return Promise.resolve(authorizationToken);\n });\n return authentication;\n }\n}\nexports.Recognizer = Recognizer;","map":{"version":3,"names":["_asyncToGenerator","require","default","Object","defineProperty","exports","value","Recognizer","Exports_js_1","Exports_js_2","Contracts_js_1","Exports_js_3","constructor","audioConfig","properties","connectionFactory","undefined","AudioConfig","fromDefaultMicrophoneInput","privDisposed","privProperties","clone","privConnectionFactory","implCommonRecognizerSetup","close","cb","errorCb","Contracts","throwIfDisposed","marshalPromiseToCallbacks","dispose","internalData","privReco","disposing","_this","audioSource","turnOff","telemetryEnabled","ServiceRecognizerBase","telemetryDataEnabled","enableTelemetry","enabled","osPlatform","window","osName","osVersion","navigator","platform","userAgent","appVersion","recognizerConfig","createRecognizerConfig","SpeechServiceConfig","Context","OS","createServiceRecognizer","getAuthFromProperties","recognizeOnceAsyncImpl","recognitionMode","_this2","ret","Deferred","implRecognizerStop","recognize","resolve","reject","result","promise","startContinuousRecognitionAsyncImpl","_this3","stopContinuousRecognitionAsyncImpl","_this4","_this5","stopRecognizing","subscriptionKey","getProperty","PropertyId","SpeechServiceConnection_Key","authentication","CognitiveSubscriptionKeyAuthentication","CognitiveTokenAuthentication","authorizationToken","SpeechServiceAuthorization_Token","Promise"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/microsoft-cognitiveservices-speech-sdk/distrib/lib/src/sdk/Recognizer.js"],"sourcesContent":["\"use strict\";\n// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT license.\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.Recognizer = void 0;\nconst Exports_js_1 = require(\"../common.speech/Exports.js\");\nconst Exports_js_2 = require(\"../common/Exports.js\");\nconst Contracts_js_1 = require(\"./Contracts.js\");\nconst Exports_js_3 = require(\"./Exports.js\");\n/**\n * Defines the base class Recognizer which mainly contains common event handlers.\n * @class Recognizer\n */\nclass Recognizer {\n /**\n * Creates and initializes an instance of a Recognizer\n * @constructor\n * @param {AudioConfig} audioInput - An optional audio input stream associated with the recognizer\n * @param {PropertyCollection} properties - A set of properties to set on the recognizer\n * @param {IConnectionFactory} connectionFactory - The factory class used to create a custom IConnection for the recognizer\n */\n constructor(audioConfig, properties, connectionFactory) {\n this.audioConfig = (audioConfig !== undefined) ? audioConfig : Exports_js_3.AudioConfig.fromDefaultMicrophoneInput();\n this.privDisposed = false;\n this.privProperties = properties.clone();\n this.privConnectionFactory = connectionFactory;\n this.implCommonRecognizerSetup();\n }\n /**\n * Dispose of associated resources.\n * @member Recognizer.prototype.close\n * @function\n * @public\n */\n close(cb, errorCb) {\n Contracts_js_1.Contracts.throwIfDisposed(this.privDisposed);\n Exports_js_2.marshalPromiseToCallbacks(this.dispose(true), cb, errorCb);\n }\n /**\n * @Internal\n * Internal data member to support fromRecognizer* pattern methods on other classes.\n * Do not use externally, object returned will change without warning or notice.\n */\n get internalData() {\n return this.privReco;\n }\n /**\n * This method performs cleanup of resources.\n * The Boolean parameter disposing indicates whether the method is called\n * from Dispose (if disposing is true) or from the finalizer (if disposing is false).\n * Derived classes should override this method to dispose resource if needed.\n * @member Recognizer.prototype.dispose\n * @function\n * @public\n * @param {boolean} disposing - Flag to request disposal.\n */\n async dispose(disposing) {\n if (this.privDisposed) {\n return;\n }\n this.privDisposed = true;\n if (disposing) {\n if (this.privReco) {\n await this.privReco.audioSource.turnOff();\n await this.privReco.dispose();\n }\n }\n }\n /**\n * This method returns the current state of the telemetry setting.\n * @member Recognizer.prototype.telemetryEnabled\n * @function\n * @public\n * @returns true if the telemetry is enabled, false otherwise.\n */\n static get telemetryEnabled() {\n return Exports_js_1.ServiceRecognizerBase.telemetryDataEnabled;\n }\n /**\n * This method globally enables or disables telemetry.\n * @member Recognizer.prototype.enableTelemetry\n * @function\n * @public\n * @param enabled - Global setting for telemetry collection.\n * If set to true, telemetry information like microphone errors,\n * recognition errors are collected and sent to Microsoft.\n * If set to false, no telemetry is sent to Microsoft.\n */\n static enableTelemetry(enabled) {\n Exports_js_1.ServiceRecognizerBase.telemetryDataEnabled = enabled;\n }\n // Does the generic recognizer setup that is common across all recognizer types.\n implCommonRecognizerSetup() {\n let osPlatform = (typeof window !== \"undefined\") ? \"Browser\" : \"Node\";\n let osName = \"unknown\";\n let osVersion = \"unknown\";\n if (typeof navigator !== \"undefined\") {\n osPlatform = osPlatform + \"/\" + navigator.platform;\n osName = navigator.userAgent;\n osVersion = navigator.appVersion;\n }\n const recognizerConfig = this.createRecognizerConfig(new Exports_js_1.SpeechServiceConfig(new Exports_js_1.Context(new Exports_js_1.OS(osPlatform, osName, osVersion))));\n this.privReco = this.createServiceRecognizer(Recognizer.getAuthFromProperties(this.privProperties), this.privConnectionFactory, this.audioConfig, recognizerConfig);\n }\n async recognizeOnceAsyncImpl(recognitionMode) {\n Contracts_js_1.Contracts.throwIfDisposed(this.privDisposed);\n const ret = new Exports_js_2.Deferred();\n await this.implRecognizerStop();\n await this.privReco.recognize(recognitionMode, ret.resolve, ret.reject);\n const result = await ret.promise;\n await this.implRecognizerStop();\n return result;\n }\n async startContinuousRecognitionAsyncImpl(recognitionMode) {\n Contracts_js_1.Contracts.throwIfDisposed(this.privDisposed);\n await this.implRecognizerStop();\n await this.privReco.recognize(recognitionMode, undefined, undefined);\n }\n async stopContinuousRecognitionAsyncImpl() {\n Contracts_js_1.Contracts.throwIfDisposed(this.privDisposed);\n await this.implRecognizerStop();\n }\n async implRecognizerStop() {\n if (this.privReco) {\n await this.privReco.stopRecognizing();\n }\n return;\n }\n static getAuthFromProperties(properties) {\n const subscriptionKey = properties.getProperty(Exports_js_3.PropertyId.SpeechServiceConnection_Key, undefined);\n const authentication = (subscriptionKey && subscriptionKey !== \"\") ?\n new Exports_js_1.CognitiveSubscriptionKeyAuthentication(subscriptionKey) :\n new Exports_js_1.CognitiveTokenAuthentication(() => {\n const authorizationToken = properties.getProperty(Exports_js_3.PropertyId.SpeechServiceAuthorization_Token, undefined);\n return Promise.resolve(authorizationToken);\n }, () => {\n const authorizationToken = properties.getProperty(Exports_js_3.PropertyId.SpeechServiceAuthorization_Token, undefined);\n return Promise.resolve(authorizationToken);\n });\n return authentication;\n }\n}\nexports.Recognizer = Recognizer;\n\n"],"mappings":"AAAA,YAAY;;AACZ;AACA;AAAA,IAAAA,iBAAA,GAAAC,OAAA,qGAAAC,OAAA;AACAC,MAAM,CAACC,cAAc,CAACC,OAAO,EAAE,YAAY,EAAE;EAAEC,KAAK,EAAE;AAAK,CAAC,CAAC;AAC7DD,OAAO,CAACE,UAAU,GAAG,KAAK,CAAC;AAC3B,MAAMC,YAAY,GAAGP,OAAO,CAAC,6BAA6B,CAAC;AAC3D,MAAMQ,YAAY,GAAGR,OAAO,CAAC,sBAAsB,CAAC;AACpD,MAAMS,cAAc,GAAGT,OAAO,CAAC,gBAAg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