native_whisperx/config/
output.rs1use std::path::PathBuf;
4
5use serde::{Deserialize, Serialize};
6
7use super::defaults::{default_output_formats, default_pretty_json};
8
9#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
10#[serde(rename_all = "camelCase")]
11pub struct OutputConfig {
12 #[serde(default)]
13 pub output_dir: Option<PathBuf>,
14 #[serde(default = "default_output_formats")]
15 pub formats: Vec<OutputFormat>,
16 #[serde(default)]
17 pub basename: Option<String>,
18 #[serde(default = "default_pretty_json")]
19 pub pretty_json: bool,
20 #[serde(default)]
21 pub subtitles: SubtitleConfig,
22}
23
24impl Default for OutputConfig {
25 fn default() -> Self {
26 Self {
27 output_dir: None,
28 formats: default_output_formats(),
29 basename: None,
30 pretty_json: true,
31 subtitles: SubtitleConfig::default(),
32 }
33 }
34}
35
36#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
37#[serde(rename_all = "lowercase")]
38pub enum OutputFormat {
39 All,
40 Json,
41 #[serde(rename = "native-json", alias = "nativeJson")]
42 NativeJson,
43 Srt,
44 Vtt,
45 Txt,
46 Tsv,
47 #[serde(rename = "aud", alias = "audacity")]
48 Audacity,
49}
50
51impl OutputFormat {
52 pub fn extension(self) -> &'static str {
53 match self {
54 Self::All => "all",
55 Self::Json => "json",
56 Self::NativeJson => "native.json",
57 Self::Srt => "srt",
58 Self::Vtt => "vtt",
59 Self::Txt => "txt",
60 Self::Tsv => "tsv",
61 Self::Audacity => "aud",
62 }
63 }
64
65 pub fn as_transcription_format(self) -> &'static str {
66 match self {
67 Self::All => "all",
68 Self::Json => "json",
69 Self::NativeJson => "native-json",
70 Self::Srt => "srt",
71 Self::Vtt => "vtt",
72 Self::Txt => "txt",
73 Self::Tsv => "tsv",
74 Self::Audacity => "aud",
75 }
76 }
77}
78
79#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
80#[serde(rename_all = "camelCase")]
81pub struct SubtitleConfig {
82 #[serde(default)]
83 pub max_line_width: Option<usize>,
84 #[serde(default)]
85 pub max_line_count: Option<usize>,
86 #[serde(default)]
87 pub highlight_words: bool,
88 #[serde(default)]
89 pub segment_resolution: SegmentResolution,
90}
91
92impl Default for SubtitleConfig {
93 fn default() -> Self {
94 Self {
95 max_line_width: None,
96 max_line_count: None,
97 highlight_words: false,
98 segment_resolution: SegmentResolution::Sentence,
99 }
100 }
101}
102
103#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
104#[serde(rename_all = "lowercase")]
105pub enum SegmentResolution {
106 #[default]
107 #[serde(alias = "segment")]
108 Sentence,
109 Chunk,
110}