@euirim/microsoft-cognitiveservices-speech-sdk
Version:
Microsoft Cognitive Services Speech SDK for JavaScript
1 lines • 14.2 kB
Source Map (JSON)
{"version":3,"sources":["src/sdk/TranslationRecognizer.ts"],"names":[],"mappings":"AAGA,OAAO,EACH,eAAe,EACf,kBAAkB,EAElB,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EAGtB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EACH,WAAW,EACX,kBAAkB,EAElB,UAAU,EACV,uCAAuC,EACvC,+BAA+B,EAC/B,4BAA4B,EAC5B,6BAA6B,EAChC,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,uBAAuB,EAA+B,MAAM,2BAA2B,CAAC;AAEjG;;;GAGG;AACH,qBAAa,qBAAsB,SAAQ,UAAU;IACjD,OAAO,CAAC,iCAAiC,CAAU;IAEnD;;;;;OAKG;gBACgB,YAAY,EAAE,uBAAuB,EAAE,WAAW,CAAC,EAAE,WAAW;IAwBnF;;;;;OAKG;IACI,WAAW,EAAE,CAAC,MAAM,EAAE,qBAAqB,EAAE,KAAK,EAAE,+BAA+B,KAAK,IAAI,CAAC;IAEpG;;;;;OAKG;IACI,UAAU,EAAE,CAAC,MAAM,EAAE,qBAAqB,EAAE,KAAK,EAAE,+BAA+B,KAAK,IAAI,CAAC;IAEnG;;;;;OAKG;IACI,QAAQ,EAAE,CAAC,MAAM,EAAE,qBAAqB,EAAE,KAAK,EAAE,uCAAuC,KAAK,IAAI,CAAC;IAEzG;;;;;OAKG;IACI,YAAY,EAAE,CAAC,MAAM,EAAE,qBAAqB,EAAE,KAAK,EAAE,6BAA6B,KAAK,IAAI,CAAC;IAEnG;;;;;;OAMG;aACQ,yBAAyB,EAAI,MAAM;IAM9C;;;;;;;OAOG;aACQ,eAAe,EAAI,MAAM,EAAE;IAMtC;;;;;;OAMG;aACQ,SAAS,EAAI,MAAM;IAM9B;;;;;;OAMG;;;;;;;;IACQ,kBAAkB,EAAI,MAAM;IAevC;;;;;;OAMG;aACQ,UAAU,EAAI,kBAAkB;IAI3C;;;;;;;;;;;OAWG;IACI,kBAAkB,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,4BAA4B,KAAK,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IAmC1G;;;;;;;;OAQG;IACI,+BAA+B,CAAC,EAAE,CAAC,EAAE,MAAM,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IAmCxF;;;;;;;OAOG;IACI,8BAA8B,CAAC,EAAE,CAAC,EAAE,MAAM,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IA+BvF;;;;;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;CAMjE","file":"TranslationRecognizer.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT license.\n\nimport {\n IAuthentication,\n IConnectionFactory,\n RecognitionMode,\n RecognizerConfig,\n ServiceRecognizerBase,\n SpeechServiceConfig,\n TranslationConnectionFactory,\n TranslationServiceRecognizer,\n} from \"../common.speech/Exports\";\nimport { AudioConfigImpl } from \"./Audio/AudioConfig\";\nimport { Contracts } from \"./Contracts\";\nimport {\n AudioConfig,\n PropertyCollection,\n PropertyId,\n Recognizer,\n TranslationRecognitionCanceledEventArgs,\n TranslationRecognitionEventArgs,\n TranslationRecognitionResult,\n TranslationSynthesisEventArgs,\n} from \"./Exports\";\nimport { SpeechTranslationConfig, SpeechTranslationConfigImpl } from \"./SpeechTranslationConfig\";\n\n/**\n * Translation recognizer\n * @class TranslationRecognizer\n */\nexport class TranslationRecognizer extends Recognizer {\n private privDisposedTranslationRecognizer: boolean;\n\n /**\n * Initializes an instance of the TranslationRecognizer.\n * @constructor\n * @param {SpeechTranslationConfig} speechConfig - Set of properties to configure this recognizer.\n * @param {AudioConfig} audioConfig - An optional audio config associated with the recognizer\n */\n public constructor(speechConfig: SpeechTranslationConfig, audioConfig?: AudioConfig) {\n const configImpl = speechConfig as SpeechTranslationConfigImpl;\n Contracts.throwIfNull(configImpl, \"speechConfig\");\n\n super(audioConfig, configImpl.properties, new TranslationConnectionFactory());\n\n this.privDisposedTranslationRecognizer = false;\n this.privProperties = configImpl.properties.clone();\n\n if (this.properties.getProperty(PropertyId.SpeechServiceConnection_TranslationVoice, undefined) !== undefined) {\n Contracts.throwIfNullOrWhitespace(\n this.properties.getProperty(PropertyId.SpeechServiceConnection_TranslationVoice),\n PropertyId[PropertyId.SpeechServiceConnection_TranslationVoice]);\n }\n\n Contracts.throwIfNullOrWhitespace(\n this.properties.getProperty(PropertyId.SpeechServiceConnection_TranslationToLanguages),\n PropertyId[PropertyId.SpeechServiceConnection_TranslationToLanguages]);\n\n Contracts.throwIfNullOrWhitespace(this.properties.getProperty(\n PropertyId.SpeechServiceConnection_RecoLanguage),\n PropertyId[PropertyId.SpeechServiceConnection_RecoLanguage]);\n }\n\n /**\n * The event recognizing signals that an intermediate recognition result is received.\n * @member TranslationRecognizer.prototype.recognizing\n * @function\n * @public\n */\n public recognizing: (sender: TranslationRecognizer, event: TranslationRecognitionEventArgs) => void;\n\n /**\n * The event recognized signals that a final recognition result is received.\n * @member TranslationRecognizer.prototype.recognized\n * @function\n * @public\n */\n public recognized: (sender: TranslationRecognizer, event: TranslationRecognitionEventArgs) => void;\n\n /**\n * The event canceled signals that an error occurred during recognition.\n * @member TranslationRecognizer.prototype.canceled\n * @function\n * @public\n */\n public canceled: (sender: TranslationRecognizer, event: TranslationRecognitionCanceledEventArgs) => void;\n\n /**\n * The event synthesizing signals that a translation synthesis result is received.\n * @member TranslationRecognizer.prototype.synthesizing\n * @function\n * @public\n */\n public synthesizing: (sender: TranslationRecognizer, event: TranslationSynthesisEventArgs) => void;\n\n /**\n * Gets the language name that was set when the recognizer was created.\n * @member TranslationRecognizer.prototype.speechRecognitionLanguage\n * @function\n * @public\n * @returns {string} Gets the language name that was set when the recognizer was created.\n */\n public get speechRecognitionLanguage(): string {\n Contracts.throwIfDisposed(this.privDisposedTranslationRecognizer);\n\n return this.properties.getProperty(PropertyId.SpeechServiceConnection_RecoLanguage);\n }\n\n /**\n * Gets target languages for translation that were set when the recognizer was created.\n * The language is specified in BCP-47 format. The translation will provide translated text for each of language.\n * @member TranslationRecognizer.prototype.targetLanguages\n * @function\n * @public\n * @returns {string[]} Gets target languages for translation that were set when the recognizer was created.\n */\n public get targetLanguages(): string[] {\n Contracts.throwIfDisposed(this.privDisposedTranslationRecognizer);\n\n return this.properties.getProperty(PropertyId.SpeechServiceConnection_TranslationToLanguages).split(\",\");\n }\n\n /**\n * Gets the name of output voice.\n * @member TranslationRecognizer.prototype.voiceName\n * @function\n * @public\n * @returns {string} the name of output voice.\n */\n public get voiceName(): string {\n Contracts.throwIfDisposed(this.privDisposedTranslationRecognizer);\n\n return this.properties.getProperty(PropertyId.SpeechServiceConnection_TranslationVoice, undefined);\n }\n\n /**\n * Gets the authorization token used to communicate with the service.\n * @member TranslationRecognizer.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 * Gets/Sets the authorization token used to communicate with the service.\n * @member TranslationRecognizer.prototype.authorizationToken\n * @function\n * @public\n * @param {string} value - Authorization token.\n */\n public set authorizationToken(value: string) {\n this.properties.setProperty(PropertyId.SpeechServiceAuthorization_Token, value);\n }\n\n /**\n * The collection of properties and their values defined for this TranslationRecognizer.\n * @member TranslationRecognizer.prototype.properties\n * @function\n * @public\n * @returns {PropertyCollection} The collection of properties and their values defined for this TranslationRecognizer.\n */\n public get properties(): PropertyCollection {\n return this.privProperties;\n }\n\n /**\n * Starts recognition and translation, and stops after the first utterance is recognized.\n * The task returns the translation text as result.\n * Note: recognizeOnceAsync returns when the first utterance has been recognized, so it is suitableonly\n * for single shot recognition like command or query. For long-running recognition,\n * use startContinuousRecognitionAsync() instead.\n * @member TranslationRecognizer.prototype.recognizeOnceAsync\n * @function\n * @public\n * @param cb - Callback that received the result when the translation has completed.\n * @param err - Callback invoked in case of an error.\n */\n public recognizeOnceAsync(cb?: (e: TranslationRecognitionResult) => void, err?: (e: string) => void): void {\n try {\n Contracts.throwIfDisposed(this.privDisposedTranslationRecognizer);\n\n this.implRecognizerStop();\n\n this.implRecognizerStart(\n RecognitionMode.Conversation,\n (e: TranslationRecognitionResult) => {\n this.implRecognizerStop();\n\n if (!!cb) {\n cb(e);\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 /**\n * Starts recognition and translation, until stopContinuousRecognitionAsync() is called.\n * User must subscribe to events to receive translation results.\n * @member TranslationRecognizer.prototype.startContinuousRecognitionAsync\n * @function\n * @public\n * @param cb - Callback that received the translation has started.\n * @param err - Callback invoked in case of an error.\n */\n public startContinuousRecognitionAsync(cb?: () => void, err?: (e: string) => void): void {\n try {\n Contracts.throwIfDisposed(this.privDisposedTranslationRecognizer);\n\n this.implRecognizerStop();\n\n this.implRecognizerStart(RecognitionMode.Conversation, undefined, undefined);\n\n // report result to promise.\n if (!!cb) {\n try {\n cb();\n } catch (e) {\n if (!!err) {\n err(e);\n }\n }\n cb = undefined;\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\n } else {\n err(error);\n }\n }\n\n // Destroy the recognizer.\n this.dispose(true);\n }\n }\n\n /**\n * Stops continuous recognition and translation.\n * @member TranslationRecognizer.prototype.stopContinuousRecognitionAsync\n * @function\n * @public\n * @param cb - Callback that received the translation has stopped.\n * @param err - Callback invoked in case of an error.\n */\n public stopContinuousRecognitionAsync(cb?: () => void, err?: (e: string) => void): void {\n try {\n Contracts.throwIfDisposed(this.privDisposedTranslationRecognizer);\n\n this.implRecognizerStop();\n\n if (!!cb) {\n try {\n cb();\n } catch (e) {\n if (!!err) {\n err(e);\n }\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\n /**\n * closes all external resources held by an instance of this class.\n * @member TranslationRecognizer.prototype.close\n * @function\n * @public\n */\n public close(): void {\n Contracts.throwIfDisposed(this.privDisposedTranslationRecognizer);\n\n this.dispose(true);\n }\n\n protected dispose(disposing: boolean): boolean {\n if (this.privDisposedTranslationRecognizer) {\n return;\n }\n\n if (disposing) {\n this.implRecognizerStop();\n this.privDisposedTranslationRecognizer = true;\n super.dispose(disposing);\n }\n }\n\n protected createRecognizerConfig(speechConfig: SpeechServiceConfig): RecognizerConfig {\n return new RecognizerConfig(speechConfig, this.properties);\n }\n\n protected createServiceRecognizer(\n authentication: IAuthentication,\n connectionFactory: IConnectionFactory,\n audioConfig: AudioConfig,\n recognizerConfig: RecognizerConfig): ServiceRecognizerBase {\n\n const configImpl: AudioConfigImpl = audioConfig as AudioConfigImpl;\n\n return new TranslationServiceRecognizer(authentication, connectionFactory, configImpl, recognizerConfig, this);\n }\n}\n"]}