@euirim/microsoft-cognitiveservices-speech-sdk
Version:
Microsoft Cognitive Services Speech SDK for JavaScript
1 lines • 10.2 kB
Source Map (JSON)
{"version":3,"sources":["src/sdk/DialogServiceConnector.ts"],"names":[],"mappings":"AAIA,OAAO,EAGH,eAAe,EACf,kBAAkB,EAElB,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACtB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAGxE,OAAO,EAAE,mBAAmB,EAA2B,MAAM,uBAAuB,CAAC;AACrF,OAAO,EACH,WAAW,EACX,kBAAkB,EAClB,UAAU,EACV,kCAAkC,EAClC,0BAA0B,EAC1B,uBAAuB,EAC1B,MAAM,WAAW,CAAC;AAGnB;;;GAGG;AACH,qBAAa,sBAAuB,SAAQ,UAAU;IAClD,OAAO,CAAC,cAAc,CAAU;IAEhC;;;;;OAKG;gBACgB,YAAY,EAAE,mBAAmB,EAAE,WAAW,CAAC,EAAE,WAAW;IAa/E;;;;;OAKG;IACI,WAAW,EAAE,CAAC,MAAM,EAAE,sBAAsB,EAAE,KAAK,EAAE,0BAA0B,KAAK,IAAI,CAAC;IAEhG;;;;;OAKG;IACI,UAAU,EAAE,CAAC,MAAM,EAAE,sBAAsB,EAAE,KAAK,EAAE,0BAA0B,KAAK,IAAI,CAAC;IAE/F;;;;;OAKG;IACI,QAAQ,EAAE,CAAC,MAAM,EAAE,sBAAsB,EAAE,KAAK,EAAE,kCAAkC,KAAK,IAAI,CAAC;IAErG;;;;;OAKG;IACI,gBAAgB,EAAE,CAAC,MAAM,EAAE,sBAAsB,EAAE,KAAK,EAAE,yBAAyB,KAAK,IAAI,CAAC;IAEpG;;;;;;;;;OASG;IACI,OAAO,IAAI,IAAI;IAItB;;;;;OAKG;IACI,UAAU,IAAI,IAAI;IAIzB;;;;;;OAMG;;;;;;;;IACQ,kBAAkB,EAAI,MAAM;IAgBvC;;;;;;OAMG;aACQ,UAAU,EAAI,kBAAkB;IAI3C;;;;;;;OAOG;IACI,eAAe,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,uBAAuB,KAAK,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IAsC3F,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAIhD;;;;;OAKG;IACI,KAAK,IAAI,IAAI;IAMpB,SAAS,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO;IAY9C,SAAS,CAAC,sBAAsB,CAAC,YAAY,EAAE,mBAAmB,GAAG,gBAAgB;IAIrF,SAAS,CAAC,uBAAuB,CAC7B,cAAc,EAAE,eAAe,EAC/B,iBAAiB,EAAE,kBAAkB,EACrC,WAAW,EAAE,WAAW,EACxB,gBAAgB,EAAE,gBAAgB,GAAG,qBAAqB;IAO9D,OAAO,CAAC,gBAAgB;CAY3B","file":"DialogServiceConnector.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT license.\n\nimport { DialogConnectionFactory } from \"../common.speech/DialogConnectorFactory\";\nimport {\n DialogServiceAdapter,\n IAgentConfig,\n IAuthentication,\n IConnectionFactory,\n RecognitionMode,\n RecognizerConfig,\n ServiceRecognizerBase,\n SpeechServiceConfig,\n} from \"../common.speech/Exports\";\nimport { ActivityReceivedEventArgs } from \"./ActivityReceivedEventArgs\";\nimport { AudioConfigImpl } from \"./Audio/AudioConfig\";\nimport { Contracts } from \"./Contracts\";\nimport { DialogServiceConfig, DialogServiceConfigImpl } from \"./DialogServiceConfig\";\nimport {\n AudioConfig,\n PropertyCollection,\n Recognizer,\n SpeechRecognitionCanceledEventArgs,\n SpeechRecognitionEventArgs,\n SpeechRecognitionResult\n} from \"./Exports\";\nimport { PropertyId } from \"./PropertyId\";\n\n/**\n * Dialog Service Connector\n * @class DialogServiceConnector\n */\nexport class DialogServiceConnector extends Recognizer {\n private privIsDisposed: boolean;\n\n /**\n * Initializes an instance of the DialogServiceConnector.\n * @constructor\n * @param {DialogServiceConfig} dialogConfig - Set of properties to configure this recognizer.\n * @param {AudioConfig} audioConfig - An optional audio config associated with the recognizer\n */\n public constructor(dialogConfig: DialogServiceConfig, audioConfig?: AudioConfig) {\n const dialogServiceConfigImpl = dialogConfig as DialogServiceConfigImpl;\n Contracts.throwIfNull(dialogConfig, \"dialogConfig\");\n\n super(audioConfig, dialogServiceConfigImpl.properties, new DialogConnectionFactory());\n\n this.privIsDisposed = false;\n this.privProperties = dialogServiceConfigImpl.properties.clone();\n\n const agentConfig = this.buildAgentConfig();\n this.privReco.agentConfig.set(agentConfig);\n }\n\n /**\n * The event recognizing signals that an intermediate recognition result is received.\n * @member DialogServiceConnector.prototype.recognizing\n * @function\n * @public\n */\n public recognizing: (sender: DialogServiceConnector, event: SpeechRecognitionEventArgs) => void;\n\n /**\n * The event recognized signals that a final recognition result is received.\n * @member DialogServiceConfig.prototype.recognized\n * @function\n * @public\n */\n public recognized: (sender: DialogServiceConnector, event: SpeechRecognitionEventArgs) => void;\n\n /**\n * The event canceled signals that an error occurred during recognition.\n * @member DialogServiceConnector.prototype.canceled\n * @function\n * @public\n */\n public canceled: (sender: DialogServiceConnector, event: SpeechRecognitionCanceledEventArgs) => void;\n\n /**\n * The event activityReceived signals that an activity has been received.\n * @member DialogServiceConnector.prototype.activityReceived\n * @function\n * @public\n */\n public activityReceived: (sender: DialogServiceConnector, event: ActivityReceivedEventArgs) => void;\n\n /**\n * Starts a connection to the service.\n * Users can optionally call connect() to manually set up a connection in advance, before starting interactions.\n *\n * Note: On return, the connection might not be ready yet. Please subscribe to the Connected event to\n * be notified when the connection is established.\n * @member DialogServiceConnector.prototype.connect\n * @function\n * @public\n */\n public connect(): void {\n this.privReco.connect();\n }\n\n /**\n * Closes the connection the service.\n * Users can optionally call disconnect() to manually shutdown the connection of the associated DialogServiceConnector.\n *\n * If disconnect() is called during a recognition, recognition will fail and cancel with an error.\n */\n public disconnect(): void {\n this.privReco.disconnect();\n }\n\n /**\n * Gets the authorization token used to communicate with the service.\n * @member DialogServiceConnector.prototype.authorizationToken\n * @function\n * @public\n * @returns {string} Authorization token.\n */\n public get authorizationToken(): string {\n return this.properties.getProperty(PropertyId.SpeechServiceAuthorization_Token);\n }\n\n /**\n * Sets the authorization token used to communicate with the service.\n * @member DialogServiceConnector.prototype.authorizationToken\n * @function\n * @public\n * @param {string} token - Authorization token.\n */\n public set authorizationToken(token: string) {\n Contracts.throwIfNullOrWhitespace(token, \"token\");\n this.properties.setProperty(PropertyId.SpeechServiceAuthorization_Token, token);\n }\n\n /**\n * The collection of properties and their values defined for this DialogServiceConnector.\n * @member DialogServiceConnector.prototype.properties\n * @function\n * @public\n * @returns {PropertyCollection} The collection of properties and their values defined for this DialogServiceConnector.\n */\n public get properties(): PropertyCollection {\n return this.privProperties;\n }\n\n /**\n * Starts recognition and stops after the first utterance is recognized.\n * @member DialogServiceConnector.prototype.listenOnceAsync\n * @function\n * @public\n * @param cb - Callback that received the result when the reco has completed.\n * @param err - Callback invoked in case of an error.\n */\n public listenOnceAsync(cb?: (e: SpeechRecognitionResult) => void, err?: (e: string) => void): void {\n try {\n Contracts.throwIfDisposed(this.privIsDisposed);\n\n this.connect();\n\n this.implRecognizerStop();\n\n this.implRecognizerStart(\n RecognitionMode.Conversation,\n (e: SpeechRecognitionResult) => {\n this.implRecognizerStop();\n\n if (!!cb) {\n cb(e);\n }\n },\n (e: string) => {\n this.implRecognizerStop();\n if (!!err) {\n err(e);\n }\n });\n } catch (error) {\n if (!!err) {\n if (error instanceof Error) {\n const typedError: Error = error as Error;\n err(typedError.name + \": \" + typedError.message);\n } else {\n err(error);\n }\n }\n\n // Destroy the recognizer.\n this.dispose(true);\n }\n }\n\n public sendActivityAsync(activity: string): void {\n this.privReco.sendMessage(activity);\n }\n\n /**\n * closes all external resources held by an instance of this class.\n * @member DialogServiceConnector.prototype.close\n * @function\n * @public\n */\n public close(): void {\n Contracts.throwIfDisposed(this.privIsDisposed);\n\n this.dispose(true);\n }\n\n protected dispose(disposing: boolean): boolean {\n if (this.privIsDisposed) {\n return;\n }\n\n if (disposing) {\n this.implRecognizerStop();\n this.privIsDisposed = true;\n super.dispose(disposing);\n }\n}\n\n protected createRecognizerConfig(speechConfig: SpeechServiceConfig): RecognizerConfig {\n return new RecognizerConfig(speechConfig, this.privProperties);\n }\n\n protected createServiceRecognizer(\n authentication: IAuthentication,\n connectionFactory: IConnectionFactory,\n audioConfig: AudioConfig,\n recognizerConfig: RecognizerConfig): ServiceRecognizerBase {\n\n const audioSource: AudioConfigImpl = audioConfig as AudioConfigImpl;\n\n return new DialogServiceAdapter(authentication, connectionFactory, audioSource, recognizerConfig, this);\n }\n\n private buildAgentConfig(): IAgentConfig {\n const communicationType = this.properties.getProperty(\"Conversation_Communication_Type\", \"Default\");\n\n return {\n botInfo: {\n commType: communicationType,\n connectionId: this.properties.getProperty(PropertyId.Conversation_ApplicationId),\n conversationId: undefined\n },\n version: 0.2\n };\n }\n}\n"]}