subx_cli/core/sync/dialogue/
segment.rs1#[derive(Debug, Clone)]
3pub struct DialogueSegment {
4 pub start_time: f64,
5 pub end_time: f64,
6 pub is_speech: bool,
7 pub confidence: f32,
8}
9
10impl DialogueSegment {
11 pub fn new_speech(start: f64, end: f64) -> Self {
13 Self {
14 start_time: start,
15 end_time: end,
16 is_speech: true,
17 confidence: 1.0,
18 }
19 }
20
21 pub fn new_silence(start: f64, end: f64) -> Self {
23 Self {
24 start_time: start,
25 end_time: end,
26 is_speech: false,
27 confidence: 1.0,
28 }
29 }
30
31 pub fn duration(&self) -> f64 {
33 self.end_time - self.start_time
34 }
35
36 pub fn overlaps_with(&self, other: &DialogueSegment) -> bool {
38 self.start_time < other.end_time && self.end_time > other.start_time
39 }
40
41 pub fn merge_with(&mut self, other: &DialogueSegment) {
43 if self.is_speech == other.is_speech && self.overlaps_with(other) {
44 self.start_time = self.start_time.min(other.start_time);
45 self.end_time = self.end_time.max(other.end_time);
46 self.confidence = (self.confidence + other.confidence) / 2.0;
47 }
48 }
49}
50
51#[derive(Debug, Clone)]
53pub struct SilenceSegment {
54 pub start_time: f64,
55 pub end_time: f64,
56 pub duration: f64,
57}
58
59impl SilenceSegment {
60 pub fn new(start: f64, end: f64) -> Self {
62 Self {
63 start_time: start,
64 end_time: end,
65 duration: end - start,
66 }
67 }
68
69 pub fn is_significant(&self, min_duration: f64) -> bool {
71 self.duration >= min_duration
72 }
73}