use anyhow::Context;
use std::path::Path;
use crate::error::GigasttError;
use crate::model::ModelVariant;
#[allow(unused_imports)]
use crate::runtime::factory::RuntimeFactory;
use crate::runtime::production_factory_variant;
use crate::runtime::tensor::{Shape, TensorDataView};
use super::audio;
use super::audio::{PcmWindows, SliceWindows, WindowSpec};
use super::bias;
use super::ctc;
use super::decode;
use super::load_files::{
ResolvedModelFiles, encoder_model_path, load_triplets_runtime, resolve_variant_required,
};
use super::pool::{Pool, SessionPool, SessionTriplet};
use super::sizing;
use super::state::{
DecoderState, EndpointMode, EndpointReason, FeatureExtractor, StreamingState,
TranscriptAssembler, TranscriptSegment, WordInfo, aggregate_confidence,
};
use super::token_format::{TokenFormatter, stitch_chunk_words};
use super::tokenizer::Tokenizer;
use super::types::{
DEFAULT_HOTWORDS_BOOST, DiarizationOutcome, HotwordError, HotwordOverride,
MAX_HOTWORD_PHRASE_CHARS, MAX_HOTWORDS_PER_REQUEST, OverrideError, TranscribeOverrides,
TranscribeRequest, TranscribeResult, TranscribeSource, merge_channel_results,
};
use super::windows::{
STREAM_DECODE_STRIDE_SAMPLES, STREAM_LEFT_CONTEXT_SAMPLES, STREAM_MAX_WINDOW_SAMPLES,
window_spec,
};
use super::{ENCODER_SUBSAMPLING, HOP_LENGTH, N_FFT, N_MELS, SECONDS_PER_FRAME, now_timestamp};
#[cfg(feature = "diarization")]
use super::diarization::{self, LazySpeakerEncoder};
#[derive(Clone, Copy, Default)]
pub(crate) struct DecodeControls<'a> {
pub(crate) abort: Option<&'a dyn Fn() -> bool>,
pub(crate) on_progress: Option<&'a dyn Fn(u64)>,
}
impl DecodeControls<'_> {
#[inline]
pub(crate) fn aborted(&self) -> bool {
self.abort.is_some_and(|a| a())
}
#[inline]
pub(crate) fn report(&self, processed_16k_samples: u64) {
if let Some(on_progress) = self.on_progress {
on_progress(processed_16k_samples);
}
}
#[inline]
pub(crate) fn abort_only(&self) -> Self {
Self {
abort: self.abort,
on_progress: None,
}
}
}
#[cfg(target_os = "android")]
const DEFAULT_POOL_SIZE: usize = 1;
#[cfg(not(target_os = "android"))]
const DEFAULT_POOL_SIZE: usize = 2;
pub struct Engine {
pub pool: SessionPool,
pub batch_pool: Option<SessionPool>,
tokenizer: Tokenizer,
features: FeatureExtractor,
variant: ModelVariant,
punctuator: Option<crate::punctuation::Punctuator>,
itn: bool,
biaser: Option<bias::Biaser>,
vad: Option<crate::vad::SileroVad>,
vad_config: crate::vad::VadConfig,
endpoint_mode: EndpointMode,
int8: bool,
ane_encoder: bool,
#[cfg(feature = "diarization")]
speaker_encoder: Option<LazySpeakerEncoder>,
}
mod api;
mod channels;
mod config;
mod file_stream;
mod infer;
mod load;
mod stream;
#[cfg(test)]
mod tests;
mod transcribe;
mod words;