@voice-ping/cognitive-services-speech
Version:
VoicePing Cognitive Services Speech SDK for JavaScript forked from Microsoft
1 lines • 14 kB
Source Map (JSON)
{"version":3,"sources":["src/sdk/SpeechRecognizer.ts"],"names":[],"mappings":"AAGA,OAAO,EACH,eAAe,EACf,kBAAkB,EAGlB,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EAEtB,MAAM,0BAA0B,CAAC;AAIlC,OAAO,EACH,WAAW,EACX,8BAA8B,EAC9B,uBAAuB,EACvB,YAAY,EACZ,kBAAkB,EAElB,UAAU,EACV,kCAAkC,EAElC,gCAAgC,EAChC,uBAAuB,EAC1B,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,YAAY,EAAoB,MAAM,gBAAgB,CAAC;AAEhE;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,UAAU;IAC5C,OAAO,CAAC,4BAA4B,CAAU;IAE9C;;;;;OAKG;gBACgB,YAAY,EAAE,YAAY,EAAE,WAAW,CAAC,EAAE,WAAW;IAYxE;;;;;;OAMG;WACW,UAAU,CAAC,YAAY,EAAE,YAAY,EAAE,8BAA8B,EAAE,8BAA8B,EAAE,WAAW,CAAC,EAAE,WAAW,GAAG,gBAAgB;IAOjK;;;;;OAKG;IACI,WAAW,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,gCAAgC,KAAK,IAAI,CAAC;IAE1F;;;;;OAKG;IACI,UAAU,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,gCAAgC,KAAK,IAAI,CAAC;IAEzF;;;;;OAKG;IACI,QAAQ,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,kCAAkC,KAAK,IAAI,CAAC;IAEzF;;;;;;OAMG;IACH,IAAW,UAAU,IAAI,MAAM,CAI9B;IAED;;;;;;OAMG;IACH,IAAW,kBAAkB,IAAI,MAAM,CAEtC;IAED;;;;;;OAMG;IACH,IAAW,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAG1C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W,EACxB,gBAAgB,EAAE,gBAAgB,GAAG,qBAAqB;CAIjE","file":"SpeechRecognizer.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT license.\n\nimport {\n IAuthentication,\n IConnectionFactory,\n OutputFormatPropertyName,\n RecognitionMode,\n RecognizerConfig,\n ServiceRecognizerBase,\n SpeechServiceConfig,\n SpeechServiceRecognizer,\n} from \"../common.speech/Exports\";\nimport { SpeechConnectionFactory } from \"../common.speech/SpeechConnectionFactory\";\nimport { AudioConfigImpl } from \"./Audio/AudioConfig\";\nimport { Contracts } from \"./Contracts\";\nimport {\n AudioConfig,\n AutoDetectSourceLanguageConfig,\n KeywordRecognitionModel,\n OutputFormat,\n PropertyCollection,\n PropertyId,\n Recognizer,\n SpeechRecognitionCanceledEventArgs,\n // SpeechRecognitionEventArgs,\n SpeechRecognitionEventArgsCustom,\n SpeechRecognitionResult,\n} from \"./Exports\";\nimport { SpeechConfig, SpeechConfigImpl } from \"./SpeechConfig\";\n\n/**\n * Performs speech recognition from microphone, file, or other audio input streams, and gets transcribed text as result.\n * @class SpeechRecognizer\n */\nexport class SpeechRecognizer extends Recognizer {\n private privDisposedSpeechRecognizer: boolean;\n\n /**\n * SpeechRecognizer constructor.\n * @constructor\n * @param {SpeechConfig} speechConfig - an set of initial properties for this recognizer\n * @param {AudioConfig} audioConfig - An optional audio configuration associated with the recognizer\n */\n public constructor(speechConfig: SpeechConfig, audioConfig?: AudioConfig) {\n const speechConfigImpl: SpeechConfigImpl = speechConfig as SpeechConfigImpl;\n Contracts.throwIfNull(speechConfigImpl, \"speechConfig\");\n\n Contracts.throwIfNullOrWhitespace(\n speechConfigImpl.properties.getProperty(PropertyId.SpeechServiceConnection_RecoLanguage),\n PropertyId[PropertyId.SpeechServiceConnection_RecoLanguage]);\n\n super(audioConfig, speechConfigImpl.properties, new SpeechConnectionFactory());\n this.privDisposedSpeechRecognizer = false;\n }\n\n /**\n * SpeechRecognizer constructor.\n * @constructor\n * @param {SpeechConfig} speechConfig - an set of initial properties for this recognizer\n * @param {AutoDetectSourceLanguageConfig} autoDetectSourceLanguageConfig - An source language detection configuration associated with the recognizer\n * @param {AudioConfig} audioConfig - An optional audio configuration associated with the recognizer\n */\n public static FromConfig(speechConfig: SpeechConfig, autoDetectSourceLanguageConfig: AutoDetectSourceLanguageConfig, audioConfig?: AudioConfig): SpeechRecognizer {\n const speechConfigImpl: SpeechConfigImpl = speechConfig as SpeechConfigImpl;\n autoDetectSourceLanguageConfig.properties.mergeTo(speechConfigImpl.properties);\n const recognizer = new SpeechRecognizer(speechConfig, audioConfig);\n return recognizer;\n }\n\n /**\n * The event recognizing signals that an intermediate recognition result is received.\n * @member SpeechRecognizer.prototype.recognizing\n * @function\n * @public\n */\n public recognizing: (sender: Recognizer, event: SpeechRecognitionEventArgsCustom) => void;\n\n /**\n * The event recognized signals that a final recognition result is received.\n * @member SpeechRecognizer.prototype.recognized\n * @function\n * @public\n */\n public recognized: (sender: Recognizer, event: SpeechRecognitionEventArgsCustom) => void;\n\n /**\n * The event canceled signals that an error occurred during recognition.\n * @member SpeechRecognizer.prototype.canceled\n * @function\n * @public\n */\n public canceled: (sender: Recognizer, event: SpeechRecognitionCanceledEventArgs) => void;\n\n /**\n * Gets the endpoint id of a customized speech model that is used for speech recognition.\n * @member SpeechRecognizer.prototype.endpointId\n * @function\n * @public\n * @returns {string} the endpoint id of a customized speech model that is used for speech recognition.\n */\n public get endpointId(): string {\n Contracts.throwIfDisposed(this.privDisposedSpeechRecognizer);\n\n return this.properties.getProperty(PropertyId.SpeechServiceConnection_EndpointId, \"00000000-0000-0000-0000-000000000000\");\n }\n\n /**\n * Gets the authorization token used to communicate with the service.\n * @member SpeechRecognizer.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 SpeechRecognizer.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 * Gets the spoken language of recognition.\n * @member SpeechRecognizer.prototype.speechRecognitionLanguage\n * @function\n * @public\n * @returns {string} The spoken language of recognition.\n */\n public get speechRecognitionLanguage(): string {\n Contracts.throwIfDisposed(this.privDisposedSpeechRecognizer);\n\n return this.properties.getProperty(PropertyId.SpeechServiceConnection_RecoLanguage);\n }\n\n /**\n * Gets the output format of recognition.\n * @member SpeechRecognizer.prototype.outputFormat\n * @function\n * @public\n * @returns {OutputFormat} The output format of recognition.\n */\n public get outputFormat(): OutputFormat {\n Contracts.throwIfDisposed(this.privDisposedSpeechRecognizer);\n\n if (this.properties.getProperty(OutputFormatPropertyName, OutputFormat[OutputFormat.Simple]) === OutputFormat[OutputFormat.Simple]) {\n return OutputFormat.Simple;\n } else {\n return OutputFormat.Detailed;\n }\n }\n\n /**\n * The collection of properties and their values defined for this SpeechRecognizer.\n * @member SpeechRecognizer.prototype.properties\n * @function\n * @public\n * @returns {PropertyCollection} The collection of properties and their values defined for this SpeechRecognizer.\n */\n public get properties(): PropertyCollection {\n return this.privProperties;\n }\n\n /**\n * Starts speech recognition, and stops after the first utterance is recognized.\n * The task returns the recognition text as result.\n * Note: RecognizeOnceAsync() returns when the first utterance has been recognized,\n * so it is suitable only for single shot recognition\n * like command or query. For long-running recognition, use StartContinuousRecognitionAsync() instead.\n * @member SpeechRecognizer.prototype.recognizeOnceAsync\n * @function\n * @public\n * @param cb - Callback that received the SpeechRecognitionResult.\n * @param err - Callback invoked in case of an error.\n */\n public recognizeOnceAsync(cb?: (e: SpeechRecognitionResult) => void, err?: (e: string) => void): void {\n this.recognizeOnceAsyncImpl(RecognitionMode.Interactive, cb, err);\n }\n\n /**\n * Starts speech recognition, until stopContinuousRecognitionAsync() is called.\n * User must subscribe to events to receive recognition results.\n * @member SpeechRecognizer.prototype.startContinuousRecognitionAsync\n * @function\n * @public\n * @param cb - Callback invoked once the recognition has started.\n * @param err - Callback invoked in case of an error.\n */\n public startContinuousRecognitionAsync(cb?: () => void, err?: (e: string) => void): void {\n this.startContinuousRecognitionAsyncImpl(RecognitionMode.Conversation, cb, err);\n }\n\n /**\n * Stops continuous speech recognition.\n * @member SpeechRecognizer.prototype.stopContinuousRecognitionAsync\n * @function\n * @public\n * @param cb - Callback invoked once the recognition has stopped.\n * @param err - Callback invoked in case of an error.\n */\n public stopContinuousRecognitionAsync(cb?: () => void, err?: (e: string) => void): void {\n this.stopContinuousRecognitionAsyncImpl(cb, err);\n }\n\n /**\n * Starts speech recognition with keyword spotting, until\n * stopKeywordRecognitionAsync() is called.\n * User must subscribe to events to receive recognition results.\n * Note: Key word spotting functionality is only available on the\n * Speech Devices SDK. This functionality is currently not included in the SDK itself.\n * @member SpeechRecognizer.prototype.startKeywordRecognitionAsync\n * @function\n * @public\n * @param {KeywordRecognitionModel} model The keyword recognition model that\n * specifies the keyword to be recognized.\n * @param cb - Callback invoked once the recognition has started.\n * @param err - Callback invoked in case of an error.\n */\n public startKeywordRecognitionAsync(model: KeywordRecognitionModel, cb?: () => void, err?: (e: string) => void): void {\n Contracts.throwIfNull(model, \"model\");\n\n if (!!err) {\n err(\"Not yet implemented.\");\n }\n }\n\n /**\n * Stops continuous speech recognition.\n * Note: Key word spotting functionality is only available on the\n * Speech Devices SDK. This functionality is currently not included in the SDK itself.\n * @member SpeechRecognizer.prototype.stopKeywordRecognitionAsync\n * @function\n * @public\n * @param cb - Callback invoked once the recognition has stopped.\n * @param err - Callback invoked in case of an error.\n */\n public stopKeywordRecognitionAsync(cb?: () => void, err?: (e: string) => void): void {\n if (!!cb) {\n cb();\n }\n }\n\n /**\n * closes all external resources held by an instance of this class.\n * @member SpeechRecognizer.prototype.close\n * @function\n * @public\n */\n public close(): void {\n Contracts.throwIfDisposed(this.privDisposedSpeechRecognizer);\n\n this.dispose(true);\n }\n\n /**\n * Disposes any resources held by the object.\n * @member SpeechRecognizer.prototype.dispose\n * @function\n * @public\n * @param {boolean} disposing - true if disposing the object.\n */\n protected dispose(disposing: boolean): void {\n if (this.privDisposedSpeechRecognizer) {\n return;\n }\n\n if (disposing) {\n this.implRecognizerStop(); // Dispose is synchronous, so just start it....\n this.privDisposedSpeechRecognizer = true;\n }\n\n super.dispose(disposing);\n }\n\n protected createRecognizerConfig(speechConfig: SpeechServiceConfig): RecognizerConfig {\n return new RecognizerConfig(\n speechConfig,\n this.properties);\n }\n\n protected createServiceRecognizer(\n authentication: IAuthentication,\n connectionFactory: IConnectionFactory,\n audioConfig: AudioConfig,\n recognizerConfig: RecognizerConfig): ServiceRecognizerBase {\n const configImpl: AudioConfigImpl = audioConfig as AudioConfigImpl;\n return new SpeechServiceRecognizer(authentication, connectionFactory, configImpl, recognizerConfig, this);\n }\n}\n"]}