"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var runner_exports = {};
__export(runner_exports, {
  EOT_INFERENCE_METHOD: () => EOT_INFERENCE_METHOD,
  default: () => EotRunner
});
module.exports = __toCommonJS(runner_exports);
var import_inference_runner = require("../../inference_runner.cjs");
var import_log = require("../../log.cjs");
var import_warmup = require("../_warmup.cjs");
const EOT_INFERENCE_METHOD = "lk_eot_audio";
class EotRunner extends import_inference_runner.InferenceRunner {
  #logger = (0, import_log.log)();
  #mod;
  async initialize() {
    this.#mod = (0, import_warmup._getLocalInferenceModule)();
    if (this.#mod === void 0) {
      throw new Error(
        "EotRunner: @livekit/local-inference native binding unavailable in the inference process"
      );
    }
    this.#mod.initEot();
  }
  async run(data) {
    if (this.#mod === void 0) {
      throw new Error("EotRunner not initialized");
    }
    const bytes = Buffer.from(data.pcm, "base64");
    const pcm = new Int16Array(bytes.buffer, bytes.byteOffset, Math.floor(bytes.byteLength / 2));
    const t0 = performance.now();
    let probability = 0;
    try {
      probability = await this.#mod.predict(pcm);
    } catch (err) {
      this.#logger.error(
        { err: err instanceof Error ? err.message : String(err) },
        "local audio EOT prediction failed"
      );
    }
    return { probability, inferenceDurationMs: performance.now() - t0 };
  }
  async close() {
    return;
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  EOT_INFERENCE_METHOD
});
//# sourceMappingURL=runner.cjs.map