//! Process-wide ONNX Runtime environment. //! //! ONNX Runtime allows a single environment per process (`ort::init().build()` //! fails on the second call), yet every [`Session`](ort::session::Session) must //! be built from it. This module lazily creates that environment once and hands //! out cheap `Arc` clones, so the STT and VAD pipelines share it. use anyhow::{Context, Result}; use ort::environment::Environment; use parking_lot::Mutex; static ENVIRONMENT: Mutex> = Mutex::new(None); /// Return the shared ONNX Runtime environment, creating it on first use. pub fn environment() -> Result { let mut guard = ENVIRONMENT.lock(); if let Some(env) = guard.as_ref() { return Ok(env.clone()); } let env = ort::init() .build() .context("failed to create ONNX Runtime environment")?; *guard = Some(env.clone()); Ok(env) }