@hahnpro/ms-speech-sdk
Version:
Microsoft Cognitive Services Speech SDK for JavaScript
1 lines • 11.7 kB
Source Map (JSON)
{"version":3,"sources":["src/sdk/Transcription/ConversationTranscriber.ts"],"names":[],"mappings":"AAGA,OAAO,EACH,eAAe,EACf,kBAAkB,EAElB,gBAAgB,EAChB,qBAAqB,EAGrB,mBAAmB,EAEtB,MAAM,gCAAgC,CAAC;AAKxC,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.\n// Licensed under the MIT license.\n\nimport {\n IAuthentication,\n IConnectionFactory,\n OutputFormatPropertyName,\n RecognizerConfig,\n ServiceRecognizerBase,\n // SpeechConnectionFactory,\n ConversationTranscriberConnectionFactory,\n SpeechServiceConfig,\n ConversationTranscriptionServiceRecognizer,\n} from \"../../common.speech/Exports.js\";\nimport { RecognitionMode } from \"../../common.speech/ServiceMessages/PhraseDetection/PhraseDetectionContext.js\";\nimport { marshalPromiseToCallbacks } from \"../../common/Exports.js\";\nimport { AudioConfigImpl } from \"../Audio/AudioConfig.js\";\nimport { Contracts } from \"../Contracts.js\";\nimport {\n AudioConfig,\n AutoDetectSourceLanguageConfig,\n ConversationTranscriptionEventArgs,\n ConversationTranscriptionCanceledEventArgs,\n OutputFormat,\n PropertyCollection,\n PropertyId,\n Recognizer,\n} from \"../Exports.js\";\nimport { SpeechConfig, SpeechConfigImpl } from \"../SpeechConfig.js\";\n\n/**\n * Performs speech recognition with speaker separation from microphone, file, or other audio input streams, and gets transcribed text as result.\n * @class ConversationTranscriber\n */\nexport class ConversationTranscriber extends Recognizer {\n private privDisposedRecognizer: boolean;\n\n /**\n * ConversationTranscriber 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 ConversationTranscriberConnectionFactory(), speechConfig.tokenCredential);\n this.privProperties.setProperty(PropertyId.SpeechServiceConnection_RecognitionEndpointVersion, \"2\");\n this.privDisposedRecognizer = false;\n }\n\n /**\n * ConversationTranscriber 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): ConversationTranscriber {\n const speechConfigImpl: SpeechConfigImpl = speechConfig as SpeechConfigImpl;\n autoDetectSourceLanguageConfig.properties.mergeTo(speechConfigImpl.properties);\n const recognizer = new ConversationTranscriber(speechConfig, audioConfig);\n return recognizer;\n }\n\n /**\n * The event transcribing signals that an intermediate transcription result is received.\n * @member ConversationTranscriber.prototype.transcribing\n * @function\n * @public\n */\n public transcribing: (sender: Recognizer, event: ConversationTranscriptionEventArgs) => void;\n\n /**\n * The event transcriber signals that a final recognition result is received.\n * @member ConversationTranscriber.prototype.transcribed\n * @function\n * @public\n */\n public transcribed: (sender: Recognizer, event: ConversationTranscriptionEventArgs) => void;\n\n /**\n * The event canceled signals that an error occurred during transcription.\n * @member ConversationTranscriber.prototype.canceled\n * @function\n * @public\n */\n public canceled: (sender: Recognizer, event: ConversationTranscriptionCanceledEventArgs) => void;\n\n /**\n * Gets the endpoint id of a customized speech model that is used for transcription.\n * @member ConversationTranscriber.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.privDisposedRecognizer);\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 ConversationTranscriber.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 ConversationTranscriber.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 transcription.\n * @member ConversationTranscriber.prototype.speechRecognitionLanguage\n * @function\n * @public\n * @returns {string} The spoken language of transcription.\n */\n public get speechRecognitionLanguage(): string {\n Contracts.throwIfDisposed(this.privDisposedRecognizer);\n\n return this.properties.getProperty(PropertyId.SpeechServiceConnection_RecoLanguage);\n }\n\n /**\n * Gets the output format of transcription.\n * @member ConversationTranscriber.prototype.outputFormat\n * @function\n * @public\n * @returns {OutputFormat} The output format of transcription.\n */\n public get outputFormat(): OutputFormat {\n Contracts.throwIfDisposed(this.privDisposedRecognizer);\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 conversation transcriber.\n * @member ConversationTranscriber.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 conversation transcription, until stopTranscribingAsync() is called.\n * User must subscribe to events to receive transcription results.\n * @member ConversationTranscriber.prototype.startTranscribingAsync\n * @function\n * @public\n * @param cb - Callback invoked once the transcription has started.\n * @param err - Callback invoked in case of an error.\n */\n public startTranscribingAsync(cb?: () => void, err?: (e: string) => void): void {\n marshalPromiseToCallbacks(this.startContinuousRecognitionAsyncImpl(RecognitionMode.Conversation), cb, err);\n }\n\n /**\n * Stops conversation transcription.\n * @member ConversationTranscriber.prototype.stopTranscribingAsync\n * @function\n * @public\n * @param cb - Callback invoked once the transcription has stopped.\n * @param err - Callback invoked in case of an error.\n */\n public stopTranscribingAsync(cb?: () => void, err?: (e: string) => void): void {\n marshalPromiseToCallbacks(this.stopContinuousRecognitionAsyncImpl(), cb, err);\n }\n\n /**\n * closes all external resources held by an instance of this class.\n * @member ConversationTranscriber.prototype.close\n * @function\n * @public\n */\n public close(cb?: () => void, errorCb?: (error: string) => void): void {\n Contracts.throwIfDisposed(this.privDisposedRecognizer);\n marshalPromiseToCallbacks(this.dispose(true), cb, errorCb);\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 async dispose(disposing: boolean): Promise<void> {\n if (this.privDisposedRecognizer) {\n return;\n }\n\n if (disposing) {\n this.privDisposedRecognizer = true;\n await this.implRecognizerStop();\n }\n\n await super.dispose(disposing);\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 const configImpl: AudioConfigImpl = audioConfig as AudioConfigImpl;\n recognizerConfig.isSpeakerDiarizationEnabled = true;\n return new ConversationTranscriptionServiceRecognizer(authentication, connectionFactory, configImpl, recognizerConfig, this);\n }\n}\n"]}