microsoft-cognitiveservices-speech-sdk
Version:
Microsoft Cognitive Services Speech SDK for JavaScript
1 lines • 12.1 kB
Source Map (JSON)
{"version":3,"sources":["src/sdk/Transcription/ConversationTranscriber.ts"],"names":[],"mappings":"AAGA,OAAO,EACH,eAAe,EACf,kBAAkB,EAGlB,gBAAgB,EAChB,qBAAqB,EAGrB,mBAAmB,EAEtB,MAAM,gCAAgC,CAAC;AAIxC,OAAO,EACH,WAAW,EACX,8BAA8B,EAC9B,kCAAkC,EAClC,0CAA0C,EAC1C,YAAY,EACZ,kBAAkB,EAElB,UAAU,EACb,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAoB,MAAM,oBAAoB,CAAC;AAEpE;;;GAGG;AACH,qBAAa,uBAAwB,SAAQ,UAAU;IACnD,OAAO,CAAC,sBAAsB,CAAU;IAExC;;;;;OAKG;gBACgB,YAAY,EAAE,YAAY,EAAE,WAAW,CAAC,EAAE,WAAW;IAaxE;;;;;;OAMG;WACW,UAAU,CAAC,YAAY,EAAE,YAAY,EAAE,8BAA8B,EAAE,8BAA8B,EAAE,WAAW,CAAC,EAAE,WAAW,GAAG,uBAAuB;IAOxK;;;;;OAKG;IACI,YAAY,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,kCAAkC,KAAK,IAAI,CAAC;IAE7F;;;;;OAKG;IACI,WAAW,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,kCAAkC,KAAK,IAAI,CAAC;IAE5F;;;;;OAKG;IACI,QAAQ,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,0CAA0C,KAAK,IAAI,CAAC;IAEjG;;;;;;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;IAED;;;;;;OAMG;IACH,IAAW,yBAAyB,IAAI,MAAM,CAI7C;IAED;;;;;;OAMG;IACH,IAAW,YAAY,IAAI,YAAY,CAQtC;IAED;;;;;;OAMG;IACH,IAAW,UAAU,IAAI,kBAAkB,CAE1C;IAED;;;;;;;;OAQG;IACI,sBAAsB,CAAC,EAAE,CAAC,EAAE,MAAM,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IAI/E;;;;;;;OAOG;IACI,qBAAqB,CAAC,EAAE,CAAC,EAAE,MAAM,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IAI9E;;;;;OAKG;IACI,KAAK,CAAC,EAAE,CAAC,EAAE,MAAM,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IAKtE;;;;;;OAMG;cACa,OAAO,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAa1D,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;CAKjE","file":"ConversationTranscriber.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT license.\r\n\r\nimport {\r\n IAuthentication,\r\n IConnectionFactory,\r\n OutputFormatPropertyName,\r\n RecognitionMode,\r\n RecognizerConfig,\r\n ServiceRecognizerBase,\r\n // SpeechConnectionFactory,\r\n ConversationTranscriberConnectionFactory,\r\n SpeechServiceConfig,\r\n ConversationTranscriptionServiceRecognizer,\r\n} from \"../../common.speech/Exports.js\";\r\nimport { marshalPromiseToCallbacks } from \"../../common/Exports.js\";\r\nimport { AudioConfigImpl } from \"../Audio/AudioConfig.js\";\r\nimport { Contracts } from \"../Contracts.js\";\r\nimport {\r\n AudioConfig,\r\n AutoDetectSourceLanguageConfig,\r\n ConversationTranscriptionEventArgs,\r\n ConversationTranscriptionCanceledEventArgs,\r\n OutputFormat,\r\n PropertyCollection,\r\n PropertyId,\r\n Recognizer,\r\n} from \"../Exports.js\";\r\nimport { SpeechConfig, SpeechConfigImpl } from \"../SpeechConfig.js\";\r\n\r\n/**\r\n * Performs speech recognition with speaker separation from microphone, file, or other audio input streams, and gets transcribed text as result.\r\n * @class ConversationTranscriber\r\n */\r\nexport class ConversationTranscriber extends Recognizer {\r\n private privDisposedRecognizer: boolean;\r\n\r\n /**\r\n * ConversationTranscriber constructor.\r\n * @constructor\r\n * @param {SpeechConfig} speechConfig - an set of initial properties for this recognizer\r\n * @param {AudioConfig} audioConfig - An optional audio configuration associated with the recognizer\r\n */\r\n public constructor(speechConfig: SpeechConfig, audioConfig?: AudioConfig) {\r\n const speechConfigImpl: SpeechConfigImpl = speechConfig as SpeechConfigImpl;\r\n Contracts.throwIfNull(speechConfigImpl, \"speechConfig\");\r\n\r\n Contracts.throwIfNullOrWhitespace(\r\n speechConfigImpl.properties.getProperty(PropertyId.SpeechServiceConnection_RecoLanguage),\r\n PropertyId[PropertyId.SpeechServiceConnection_RecoLanguage]);\r\n\r\n super(audioConfig, speechConfigImpl.properties, new ConversationTranscriberConnectionFactory());\r\n this.privProperties.setProperty(PropertyId.SpeechServiceConnection_RecognitionEndpointVersion, \"2\");\r\n this.privDisposedRecognizer = false;\r\n }\r\n\r\n /**\r\n * ConversationTranscriber constructor.\r\n * @constructor\r\n * @param {SpeechConfig} speechConfig - an set of initial properties for this recognizer\r\n * @param {AutoDetectSourceLanguageConfig} autoDetectSourceLanguageConfig - An source language detection configuration associated with the recognizer\r\n * @param {AudioConfig} audioConfig - An optional audio configuration associated with the recognizer\r\n */\r\n public static FromConfig(speechConfig: SpeechConfig, autoDetectSourceLanguageConfig: AutoDetectSourceLanguageConfig, audioConfig?: AudioConfig): ConversationTranscriber {\r\n const speechConfigImpl: SpeechConfigImpl = speechConfig as SpeechConfigImpl;\r\n autoDetectSourceLanguageConfig.properties.mergeTo(speechConfigImpl.properties);\r\n const recognizer = new ConversationTranscriber(speechConfig, audioConfig);\r\n return recognizer;\r\n }\r\n\r\n /**\r\n * The event transcribing signals that an intermediate transcription result is received.\r\n * @member ConversationTranscriber.prototype.transcribing\r\n * @function\r\n * @public\r\n */\r\n public transcribing: (sender: Recognizer, event: ConversationTranscriptionEventArgs) => void;\r\n\r\n /**\r\n * The event transcriber signals that a final recognition result is received.\r\n * @member ConversationTranscriber.prototype.transcribed\r\n * @function\r\n * @public\r\n */\r\n public transcribed: (sender: Recognizer, event: ConversationTranscriptionEventArgs) => void;\r\n\r\n /**\r\n * The event canceled signals that an error occurred during transcription.\r\n * @member ConversationTranscriber.prototype.canceled\r\n * @function\r\n * @public\r\n */\r\n public canceled: (sender: Recognizer, event: ConversationTranscriptionCanceledEventArgs) => void;\r\n\r\n /**\r\n * Gets the endpoint id of a customized speech model that is used for transcription.\r\n * @member ConversationTranscriber.prototype.endpointId\r\n * @function\r\n * @public\r\n * @returns {string} the endpoint id of a customized speech model that is used for speech recognition.\r\n */\r\n public get endpointId(): string {\r\n Contracts.throwIfDisposed(this.privDisposedRecognizer);\r\n\r\n return this.properties.getProperty(PropertyId.SpeechServiceConnection_EndpointId, \"00000000-0000-0000-0000-000000000000\");\r\n }\r\n\r\n /**\r\n * Gets the authorization token used to communicate with the service.\r\n * @member ConversationTranscriber.prototype.authorizationToken\r\n * @function\r\n * @public\r\n * @returns {string} Authorization token.\r\n */\r\n public get authorizationToken(): string {\r\n return this.properties.getProperty(PropertyId.SpeechServiceAuthorization_Token);\r\n }\r\n\r\n /**\r\n * Gets/Sets the authorization token used to communicate with the service.\r\n * @member ConversationTranscriber.prototype.authorizationToken\r\n * @function\r\n * @public\r\n * @param {string} token - Authorization token.\r\n */\r\n public set authorizationToken(token: string) {\r\n Contracts.throwIfNullOrWhitespace(token, \"token\");\r\n this.properties.setProperty(PropertyId.SpeechServiceAuthorization_Token, token);\r\n }\r\n\r\n /**\r\n * Gets the spoken language of transcription.\r\n * @member ConversationTranscriber.prototype.speechRecognitionLanguage\r\n * @function\r\n * @public\r\n * @returns {string} The spoken language of transcription.\r\n */\r\n public get speechRecognitionLanguage(): string {\r\n Contracts.throwIfDisposed(this.privDisposedRecognizer);\r\n\r\n return this.properties.getProperty(PropertyId.SpeechServiceConnection_RecoLanguage);\r\n }\r\n\r\n /**\r\n * Gets the output format of transcription.\r\n * @member ConversationTranscriber.prototype.outputFormat\r\n * @function\r\n * @public\r\n * @returns {OutputFormat} The output format of transcription.\r\n */\r\n public get outputFormat(): OutputFormat {\r\n Contracts.throwIfDisposed(this.privDisposedRecognizer);\r\n\r\n if (this.properties.getProperty(OutputFormatPropertyName, OutputFormat[OutputFormat.Simple]) === OutputFormat[OutputFormat.Simple]) {\r\n return OutputFormat.Simple;\r\n } else {\r\n return OutputFormat.Detailed;\r\n }\r\n }\r\n\r\n /**\r\n * The collection of properties and their values defined for this conversation transcriber.\r\n * @member ConversationTranscriber.prototype.properties\r\n * @function\r\n * @public\r\n * @returns {PropertyCollection} The collection of properties and their values defined for this SpeechRecognizer.\r\n */\r\n public get properties(): PropertyCollection {\r\n return this.privProperties;\r\n }\r\n\r\n /**\r\n * Starts conversation transcription, until stopTranscribingAsync() is called.\r\n * User must subscribe to events to receive transcription results.\r\n * @member ConversationTranscriber.prototype.startTranscribingAsync\r\n * @function\r\n * @public\r\n * @param cb - Callback invoked once the transcription has started.\r\n * @param err - Callback invoked in case of an error.\r\n */\r\n public startTranscribingAsync(cb?: () => void, err?: (e: string) => void): void {\r\n marshalPromiseToCallbacks(this.startContinuousRecognitionAsyncImpl(RecognitionMode.Conversation), cb, err);\r\n }\r\n\r\n /**\r\n * Stops conversation transcription.\r\n * @member ConversationTranscriber.prototype.stopTranscribingAsync\r\n * @function\r\n * @public\r\n * @param cb - Callback invoked once the transcription has stopped.\r\n * @param err - Callback invoked in case of an error.\r\n */\r\n public stopTranscribingAsync(cb?: () => void, err?: (e: string) => void): void {\r\n marshalPromiseToCallbacks(this.stopContinuousRecognitionAsyncImpl(), cb, err);\r\n }\r\n\r\n /**\r\n * closes all external resources held by an instance of this class.\r\n * @member ConversationTranscriber.prototype.close\r\n * @function\r\n * @public\r\n */\r\n public close(cb?: () => void, errorCb?: (error: string) => void): void {\r\n Contracts.throwIfDisposed(this.privDisposedRecognizer);\r\n marshalPromiseToCallbacks(this.dispose(true), cb, errorCb);\r\n }\r\n\r\n /**\r\n * Disposes any resources held by the object.\r\n * @member SpeechRecognizer.prototype.dispose\r\n * @function\r\n * @public\r\n * @param {boolean} disposing - true if disposing the object.\r\n */\r\n protected async dispose(disposing: boolean): Promise<void> {\r\n if (this.privDisposedRecognizer) {\r\n return;\r\n }\r\n\r\n if (disposing) {\r\n this.privDisposedRecognizer = true;\r\n await this.implRecognizerStop();\r\n }\r\n\r\n await super.dispose(disposing);\r\n }\r\n\r\n protected createRecognizerConfig(speechConfig: SpeechServiceConfig): RecognizerConfig {\r\n return new RecognizerConfig(speechConfig, this.privProperties);\r\n }\r\n\r\n protected createServiceRecognizer(\r\n authentication: IAuthentication,\r\n connectionFactory: IConnectionFactory,\r\n audioConfig: AudioConfig,\r\n recognizerConfig: RecognizerConfig): ServiceRecognizerBase {\r\n const configImpl: AudioConfigImpl = audioConfig as AudioConfigImpl;\r\n recognizerConfig.isSpeakerDiarizationEnabled = true;\r\n return new ConversationTranscriptionServiceRecognizer(authentication, connectionFactory, configImpl, recognizerConfig, this);\r\n }\r\n}\r\n"]}