import { InferenceRunner } from "../../inference_runner.js";
import { log } from "../../log.js";
import { _getLocalInferenceModule } from "../_warmup.js";
const EOT_INFERENCE_METHOD = "lk_eot_audio";
class EotRunner extends InferenceRunner {
  #logger = log();
  #mod;
  async initialize() {
    this.#mod = _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;
  }
}
export {
  EOT_INFERENCE_METHOD,
  EotRunner as default
};
//# sourceMappingURL=runner.js.map