in libs/voicefocus/voicefocus.js [145:208]
static configure(spec, options) {
return __awaiter(this, void 0, void 0, function* () {
const { fetchBehavior, preResolve, logger, } = options || {};
const { category = 'voicefocus', name = 'default', variant: variantPreference = 'auto', assetGroup = DEFAULT_ASSET_GROUP, revisionID, simd = 'detect', executionPreference = 'auto', executionQuantaPreference, usagePreference = 'interactivity', estimatorBudget = 100, paths = DEFAULT_PATHS, thresholds, } = spec || {};
logger === null || logger === void 0 ? void 0 : logger.debug('Configuring Voice Focus with spec', spec);
if (category !== undefined && category !== 'voicefocus') {
throw new Error(`Unrecognized category ${category}`);
}
if (name !== undefined && name !== 'default' && name !== 'ns_es') {
throw new Error(`Unrecognized feature name ${name}`);
}
if (variantPreference !== undefined && !['auto', 'c100', 'c50', 'c20', 'c10'].includes(variantPreference)) {
throw new Error(`Unrecognized feature variant ${variantPreference}`);
}
if (executionQuantaPreference !== undefined && ![1, 2, 3].includes(executionQuantaPreference)) {
throw new Error(`Unrecognized execution quanta preference ${executionQuantaPreference}`);
}
validateAssetSpec(assetGroup, revisionID);
if (simd !== undefined && !['detect', 'force', 'disable'].includes(simd)) {
throw new Error(`Unrecognized SIMD option ${simd}`);
}
if (executionPreference !== undefined && !['auto', 'inline', 'worker', 'worker-sab', 'worker-postMessage'].includes(executionPreference)) {
throw new Error(`Unrecognized execution preference ${executionPreference}`);
}
if (usagePreference !== undefined && !['quality', 'interactivity'].includes(usagePreference)) {
throw new Error(`Unrecognized usage preference ${usagePreference}`);
}
const executionSpec = {
executionPreference: this.mungeExecutionPreference(executionPreference, logger),
usagePreference,
executionQuantaPreference,
variantPreference,
namePreference: name,
simdPreference: simd,
estimatorBudget,
};
const assetConfig = revisionID ? { revisionID } : { assetGroup };
const updatedFetchBehavior = fetch_js_1.addQueryParams(fetchBehavior, assetConfig);
const fetchConfig = Object.assign({ paths }, updatedFetchBehavior);
const executionDefinition = yield decider_js_1.measureAndDecideExecutionApproach(executionSpec, fetchConfig, logger, thresholds);
if (executionDefinition.supported === false) {
return { supported: false, reason: executionDefinition.reason };
}
logger === null || logger === void 0 ? void 0 : logger.info('Decided execution approach', executionDefinition);
const { useSIMD, processor, variant, executionQuanta } = executionDefinition;
const model = {
category: category || 'voicefocus',
name: name || 'default',
variant,
simd: useSIMD,
};
if (preResolve) {
const startingURL = urlForModel(model, paths);
model.url = yield fetch_js_1.resolveURL(startingURL, updatedFetchBehavior);
}
return {
fetchConfig,
model,
processor,
executionQuanta,
supported: true,
};
});
}