in libs/voicefocus/voicefocus.js [209:256]
static init(configuration, { delegate, preload = true, logger, }) {
return __awaiter(this, void 0, void 0, function* () {
if (configuration.supported === false) {
throw new Error('Voice Focus not supported. Reason: ' + configuration.reason);
}
const { model, processor, fetchConfig, executionQuanta, } = configuration;
const { simd, name } = model;
const { paths } = fetchConfig;
if (processor !== 'voicefocus-inline-processor' &&
processor !== 'voicefocus-worker-postMessage-processor' &&
processor !== 'voicefocus-worker-sab-processor') {
throw new Error(`Unknown processor ${processor}`);
}
const modelURL = model.url || urlForModel(model, paths);
logger === null || logger === void 0 ? void 0 : logger.debug(`Using model URL ${modelURL}.`);
const audioBufferURL = `${paths.wasm}audio_buffer-v1${simd ? '_simd' : ''}.wasm`;
const resamplerURL = `${paths.wasm}resampler-v1${simd ? '_simd' : ''}.wasm`;
const workerURL = `${paths.workers}worker-v1.js`;
const { file, node } = PROCESSORS[processor];
const processorURL = `${paths.processors}${file}`;
const worker = yield loader_js_1.loadWorker(workerURL, 'VoiceFocusWorker', fetchConfig, logger);
if (preload) {
logger === null || logger === void 0 ? void 0 : logger.debug('Preloading', modelURL);
let message = support_js_1.supportsWASMPostMessage(globalThis) ? 'get-module' : 'get-module-buffer';
worker.postMessage({
message,
preload: true,
key: 'model',
fetchBehavior: fetchConfig,
path: modelURL,
});
}
const numberOfInputs = (name === 'ns_es') ? 2 : 1;
const nodeOptions = {
processor,
worker,
audioBufferURL,
resamplerURL,
fetchBehavior: fetchConfig,
modelURL,
delegate,
logger,
numberOfInputs,
};
const factory = new VoiceFocus(worker, processorURL, node, nodeOptions, executionQuanta);
return Promise.resolve(factory);
});
}