subx_cli/core/sync/
dialogue.rs

1pub mod analyzer;
2pub mod detector;
3pub mod segment;
4
5pub use analyzer::EnergyAnalyzer;
6pub use detector::DialogueDetector;
7pub use segment::{DialogueSegment, SilenceSegment};
8
9#[cfg(test)]
10mod tests {
11    use super::*;
12    use crate::config::init_config_manager;
13    use tempfile::TempDir;
14
15    #[test]
16    fn test_config_loading() {
17        init_config_manager().unwrap();
18        let cfg = crate::config::load_config().unwrap();
19        assert!(cfg.sync.dialogue_detection_threshold > 0.0);
20        assert!(cfg.sync.min_dialogue_duration_ms > 0);
21        assert!(cfg.sync.dialogue_merge_gap_ms > 0);
22        assert!(cfg.sync.enable_dialogue_detection);
23    }
24
25    #[test]
26    fn test_dialogue_segment_operations() {
27        let mut s1 = DialogueSegment::new_speech(1.0, 3.0);
28        let s2 = DialogueSegment::new_speech(2.5, 4.0);
29        assert!(s1.overlaps_with(&s2));
30        assert_eq!(s1.duration(), 2.0);
31        s1.merge_with(&s2);
32        assert_eq!(s1.end_time, 4.0);
33    }
34
35    #[test]
36    fn test_energy_analyzer_basic() {
37        let analyzer = EnergyAnalyzer::new(0.01, 500);
38        let sample_audio = vec![0.0; 44100];
39        let segs = analyzer.analyze(&sample_audio, 44100);
40        assert!(segs.iter().all(|s| !s.is_speech));
41    }
42
43    #[tokio::test]
44    #[ignore]
45    async fn test_dialogue_detector_integration() {
46        let temp = TempDir::new().unwrap();
47        let audio_path = temp.path().join("test.wav");
48        // TODO: 實際測試需提供真實音訊檔案
49        let detector = DialogueDetector::new().unwrap();
50        let segs = detector.detect_dialogue(&audio_path).await.unwrap();
51        assert!(segs.is_empty());
52    }
53}