UNPKG

@voice-ping/cognitive-services-speech

Version:

VoicePing Cognitive Services Speech SDK for JavaScript forked from Microsoft

1 lines 7.28 kB
{"version":3,"sources":["src/sdk/SpeakerRecognizer.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,WAAW,EAAmB,MAAM,qBAAqB,CAAC;AAEnE,OAAO,EACH,kBAAkB,EAGlB,0BAA0B,EAC1B,wBAAwB,EAExB,wBAAwB,EAE3B,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,YAAY,EAAoB,MAAM,gBAAgB,CAAC;AAEhE;;;;GAIG;AACH,qBAAa,iBAAiB;IAC1B,SAAS,CAAC,cAAc,EAAE,kBAAkB,CAAC;IAC7C,OAAO,CAAC,WAAW,CAA0B;IAC7C,OAAO,CAAC,mBAAmB,CAAkB;IAE7C;;;;;;OAMG;IACH,IAAW,kBAAkB,IAAI,MAAM,CAEtC;IAED;;;;;;OAMG;IACH,IAAW,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAG1C;IAED;;;;;;OAMG;IACH,IAAW,UAAU,IAAI,kBAAkB,CAE1C;IAED;;;;OAIG;gBACgB,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW;IAWvE;;;;;;;;OAQG;IACI,kBAAkB,CAAC,KAAK,EAAE,0BAA0B,GAAG,wBAAwB,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,wBAAwB,KAAK,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IAcpK;;;;;OAKG;IACI,KAAK,IAAI,IAAI;IAKpB,OAAO,CAAC,WAAW;IAoBnB,OAAO,CAAC,qBAAqB;CAuBhC","file":"SpeakerRecognizer.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT license.\n\nimport {\n IRestResponse,\n} from \"../common.browser/Exports\";\nimport {\n Context,\n OS,\n SpeakerIdMessageAdapter,\n SpeakerRecognitionConfig,\n} from \"../common.speech/Exports\";\nimport { IAudioSource, PromiseResult } from \"../common/Exports\";\nimport { AudioConfig, AudioConfigImpl } from \"./Audio/AudioConfig\";\nimport { Contracts } from \"./Contracts\";\nimport {\n PropertyCollection,\n PropertyId,\n ResultReason,\n SpeakerIdentificationModel,\n SpeakerRecognitionResult,\n SpeakerRecognitionResultType,\n SpeakerVerificationModel,\n VoiceProfile,\n} from \"./Exports\";\nimport { SpeechConfig, SpeechConfigImpl } from \"./SpeechConfig\";\n\n/**\n * Defines SpeakerRecognizer class for Speaker Recognition\n * Handles operations from user for Voice Profile operations (e.g. createProfile, deleteProfile)\n * @class SpeakerRecognizer\n */\nexport class SpeakerRecognizer {\n protected privProperties: PropertyCollection;\n private privAdapter: SpeakerIdMessageAdapter;\n private privAudioConfigImpl: AudioConfigImpl;\n\n /**\n * Gets the authorization token used to communicate with the service.\n * @member SpeakerRecognizer.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 SpeakerRecognizer.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 SpeakerRecognizer.\n * @member SpeakerRecognizer.prototype.properties\n * @function\n * @public\n * @returns {PropertyCollection} The collection of properties and their values defined for this SpeakerRecognizer.\n */\n public get properties(): PropertyCollection {\n return this.privProperties;\n }\n\n /**\n * SpeakerRecognizer constructor.\n * @constructor\n * @param {SpeechConfig} speechConfig - An set of initial properties for this recognizer (authentication key, region, &c)\n */\n public constructor(speechConfig: SpeechConfig, audioConfig: AudioConfig) {\n const speechConfigImpl: SpeechConfigImpl = speechConfig as SpeechConfigImpl;\n Contracts.throwIfNull(speechConfigImpl, \"speechConfig\");\n\n this.privAudioConfigImpl = audioConfig as AudioConfigImpl;\n Contracts.throwIfNull(this.privAudioConfigImpl, \"audioConfig\");\n\n this.privProperties = speechConfigImpl.properties.clone();\n this.implSRSetup();\n }\n\n /**\n * Get recognition result for model using given audio\n * @member SpeakerRecognizer.prototype.recognizeOnceAsync\n * @function\n * @public\n * @param {SpeakerIdentificationModel} model Model containing Voice Profiles to be identified\n * @param cb - Callback invoked once result is returned.\n * @param err - Callback invoked in case of an error.\n */\n public recognizeOnceAsync(model: SpeakerIdentificationModel | SpeakerVerificationModel, cb?: (e: SpeakerRecognitionResult) => void, err?: (e: string) => void): void {\n if (model instanceof SpeakerIdentificationModel) {\n this.privAdapter.identifySpeaker(model, this.privAudioConfigImpl).continueWith((promiseResult: PromiseResult<IRestResponse>) => {\n this.handleResultCallbacks(promiseResult, SpeakerRecognitionResultType.Identify, undefined, cb, err);\n });\n } else if (model instanceof SpeakerVerificationModel) {\n this.privAdapter.verifySpeaker(model, this.privAudioConfigImpl).continueWith((promiseResult: PromiseResult<IRestResponse>) => {\n this.handleResultCallbacks(promiseResult, SpeakerRecognitionResultType.Verify, model.voiceProfile.profileId, cb, err);\n });\n } else {\n throw new Error(\"SpeakerRecognizer.recognizeOnce: Unexpected model type\");\n }\n }\n\n /**\n * Included for compatibility\n * @member SpeakerRecognizer.prototype.close\n * @function\n * @public\n */\n public close(): void {\n return;\n }\n\n // Does class setup, swiped from Recognizer.\n private implSRSetup(): void {\n\n let osPlatform = (typeof window !== \"undefined\") ? \"Browser\" : \"Node\";\n let osName = \"unknown\";\n let osVersion = \"unknown\";\n\n if (typeof navigator !== \"undefined\") {\n osPlatform = osPlatform + \"/\" + navigator.platform;\n osName = navigator.userAgent;\n osVersion = navigator.appVersion;\n }\n\n const recognizerConfig =\n new SpeakerRecognitionConfig(\n new Context(new OS(osPlatform, osName, osVersion)),\n this.privProperties);\n\n this.privAdapter = new SpeakerIdMessageAdapter(recognizerConfig);\n }\n\n private handleResultCallbacks(promiseResult: PromiseResult<IRestResponse>, resultType: SpeakerRecognitionResultType, profileId?: string, cb?: (response: SpeakerRecognitionResult) => void, err?: (e: string) => void): void {\n try {\n if (promiseResult.isError) {\n if (!!err) {\n err(promiseResult.error);\n }\n } else if (promiseResult.isCompleted && !!cb) {\n cb(\n new SpeakerRecognitionResult(\n resultType,\n promiseResult.result.data,\n profileId,\n promiseResult.result.ok ? ResultReason.RecognizedSpeaker : ResultReason.Canceled,\n )\n );\n }\n } catch (e) {\n if (!!err) {\n err(e);\n }\n }\n }\n\n}\n"]}