@voice-ping/cognitive-services-speech
Version:
VoicePing Cognitive Services Speech SDK for JavaScript forked from Microsoft
182 lines (180 loc) • 7.59 kB
JavaScript
;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
var Exports_1 = require("../common.speech/Exports");
var Contracts_1 = require("./Contracts");
var Exports_2 = require("./Exports");
/**
* Defines VoiceProfileClient class for Speaker Recognition
* Handles operations from user for Voice Profile operations (e.g. createProfile, deleteProfile)
* @class VoiceProfileClient
*/
var VoiceProfileClient = /** @class */ (function () {
/**
* VoiceProfileClient constructor.
* @constructor
* @param {SpeechConfig} speechConfig - An set of initial properties for this synthesizer (authentication key, region, &c)
*/
function VoiceProfileClient(speechConfig) {
var speechConfigImpl = speechConfig;
Contracts_1.Contracts.throwIfNull(speechConfigImpl, "speechConfig");
this.privProperties = speechConfigImpl.properties.clone();
this.implClientSetup();
}
Object.defineProperty(VoiceProfileClient.prototype, "authorizationToken", {
/**
* Gets the authorization token used to communicate with the service.
* @member VoiceProfileClient.prototype.authorizationToken
* @function
* @public
* @returns {string} Authorization token.
*/
get: function () {
return this.properties.getProperty(Exports_2.PropertyId.SpeechServiceAuthorization_Token);
},
/**
* Gets/Sets the authorization token used to communicate with the service.
* @member VoiceProfileClient.prototype.authorizationToken
* @function
* @public
* @param {string} token - Authorization token.
*/
set: function (token) {
Contracts_1.Contracts.throwIfNullOrWhitespace(token, "token");
this.properties.setProperty(Exports_2.PropertyId.SpeechServiceAuthorization_Token, token);
},
enumerable: true,
configurable: true
});
Object.defineProperty(VoiceProfileClient.prototype, "properties", {
/**
* The collection of properties and their values defined for this VoiceProfileClient.
* @member VoiceProfileClient.prototype.properties
* @function
* @public
* @returns {PropertyCollection} The collection of properties and their values defined for this VoiceProfileClient.
*/
get: function () {
return this.privProperties;
},
enumerable: true,
configurable: true
});
/**
* Create a speaker recognition voice profile
* @member VoiceProfileClient.prototype.createProfileAsync
* @function
* @public
* @param {VoiceProfileType} profileType Type of Voice Profile to be created
* specifies the keyword to be recognized.
* @param {string} lang Language string (locale) for Voice Profile
* @param cb - Callback invoked once Voice Profile has been created.
* @param err - Callback invoked in case of an error.
*/
VoiceProfileClient.prototype.createProfileAsync = function (profileType, lang, cb, err) {
this.privAdapter.createProfile(profileType, lang).on(function (result) {
if (!!cb) {
var response = result.json();
var profile = new Exports_2.VoiceProfile(response.profileId, profileType);
cb(profile);
}
}, function (error) {
if (!!err) {
err(error);
}
});
};
/**
* Create a speaker recognition voice profile
* @member VoiceProfileClient.prototype.enrollProfileAsync
* @function
* @public
* @param {VoiceProfile} profile Voice Profile to create enrollment for
* @param {AudioConfig} audioConfig source info from which to create enrollment
* @param cb - Callback invoked once Enrollment request has been submitted.
* @param err - Callback invoked in case of an error.
*/
VoiceProfileClient.prototype.enrollProfileAsync = function (profile, audioConfig, cb, err) {
var configImpl = audioConfig;
Contracts_1.Contracts.throwIfNullOrUndefined(configImpl, "audioConfig");
this.privAdapter.createEnrollment(profile, configImpl).on(function (result) {
if (!!cb) {
cb(new Exports_2.VoiceProfileEnrollmentResult(result.ok ? Exports_2.ResultReason.EnrolledVoiceProfile : Exports_2.ResultReason.Canceled, result.data, result.statusText));
}
}, function (error) {
if (!!err) {
err(error);
}
});
};
/**
* Delete a speaker recognition voice profile
* @member VoiceProfileClient.prototype.deleteProfileAsync
* @function
* @public
* @param {VoiceProfile} profile Voice Profile to be deleted
* @param cb - Callback invoked once Voice Profile has been deleted.
* @param err - Callback invoked in case of an error.
*/
VoiceProfileClient.prototype.deleteProfileAsync = function (profile, cb, err) {
var _this = this;
this.privAdapter.deleteProfile(profile).on(function (result) {
_this.handleResultCallbacks(result, Exports_2.ResultReason.DeletedVoiceProfile, cb);
}, function (error) {
if (!!err) {
err(error);
}
});
};
/**
* Remove all enrollments for a speaker recognition voice profile
* @member VoiceProfileClient.prototype.resetProfileAsync
* @function
* @public
* @param {VoiceProfile} profile Voice Profile to be reset
* @param cb - Callback invoked once Voice Profile has been reset.
* @param err - Callback invoked in case of an error.
*/
VoiceProfileClient.prototype.resetProfileAsync = function (profile, cb, err) {
var _this = this;
this.privAdapter.resetProfile(profile).on(function (result) {
_this.handleResultCallbacks(result, Exports_2.ResultReason.ResetVoiceProfile, cb);
}, function (error) {
if (!!err) {
err(error);
}
});
};
/**
* Included for compatibility
* @member VoiceProfileClient.prototype.close
* @function
* @public
*/
VoiceProfileClient.prototype.close = function () {
return;
};
// Does class setup, swiped from Recognizer.
VoiceProfileClient.prototype.implClientSetup = function () {
var osPlatform = (typeof window !== "undefined") ? "Browser" : "Node";
var osName = "unknown";
var osVersion = "unknown";
if (typeof navigator !== "undefined") {
osPlatform = osPlatform + "/" + navigator.platform;
osName = navigator.userAgent;
osVersion = navigator.appVersion;
}
var recognizerConfig = new Exports_1.SpeakerRecognitionConfig(new Exports_1.Context(new Exports_1.OS(osPlatform, osName, osVersion)), this.privProperties);
this.privAdapter = new Exports_1.SpeakerIdMessageAdapter(recognizerConfig);
};
VoiceProfileClient.prototype.handleResultCallbacks = function (result, successReason, cb) {
if (!!cb) {
var response = new Exports_2.VoiceProfileResult(result.ok ? successReason : Exports_2.ResultReason.Canceled, result.statusText);
cb(response);
}
};
return VoiceProfileClient;
}());
exports.VoiceProfileClient = VoiceProfileClient;
//# sourceMappingURL=VoiceProfileClient.js.map