Skip to main content

native_whisperx/config/
translation.rs

1//! Optional native translation configuration applied after ASR.
2
3use std::path::PathBuf;
4
5use serde::{Deserialize, Serialize};
6
7/// Library-owned controls for post-ASR translation model resolution.
8///
9/// These controls intentionally do not depend on CLI argument types. Embedding
10/// applications can select an explicit bundle, an application model directory,
11/// or cache-only resolution without constructing a command-line configuration.
12#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
13#[serde(rename_all = "camelCase")]
14pub struct TranslationConfig {
15    /// Enables post-ASR translation for finite Workflow Composition.
16    #[serde(default)]
17    pub enabled: bool,
18    /// Hugging Face model ID used by the legacy single-model translation path.
19    #[serde(default)]
20    pub model_id: Option<String>,
21    /// Explicit local Marian model bundle, preferred over cache resolution.
22    #[serde(default)]
23    pub model_bundle: Option<PathBuf>,
24    /// Application-selected model/cache root used for translation resolution.
25    #[serde(default)]
26    pub model_dir: Option<PathBuf>,
27    /// Forbids translation model downloads and fails when local assets are absent.
28    #[serde(default)]
29    pub model_cache_only: bool,
30    /// ISO 639-1 source language code for the configured model.
31    #[serde(default)]
32    pub source_language: Option<String>,
33    /// ISO 639-1 target language code for the configured model.
34    #[serde(default)]
35    pub target_language: Option<String>,
36    /// Maximum number of tokens produced for each translated segment.
37    #[serde(default = "default_translation_max_new_tokens")]
38    pub max_new_tokens: usize,
39}
40
41impl Default for TranslationConfig {
42    fn default() -> Self {
43        Self {
44            enabled: false,
45            model_id: None,
46            model_bundle: None,
47            model_dir: None,
48            model_cache_only: false,
49            source_language: None,
50            target_language: None,
51            max_new_tokens: default_translation_max_new_tokens(),
52        }
53    }
54}
55
56fn default_translation_max_new_tokens() -> usize {
57    256
58}