batch_mode_tts/
merge.rs

1crate::ix!();
2
3impl BatchModeTtsJob {
4    // -----------------------------------------------------------------------
5    // Helper: merge with ffmpeg concat demuxer
6    // -----------------------------------------------------------------------
7    pub async fn merge_parts_ffmpeg(&self, parts: &[PathBuf]) -> Result<(), BatchModeTtsError> {
8        // Build concat‑list file
9        let list_path = self
10            .output_path()
11            .with_file_name("ffmpeg_concat_list.txt");
12        let mut list_file = File::create(&list_path)?;
13        for p in parts {
14            writeln!(list_file, "file '{}'", p.display())?;
15        }
16        drop(list_file);
17
18        // Run ffmpeg
19        let status = Command::new("ffmpeg")
20            .args([
21                "-y",
22                "-f",
23                "concat",
24                "-safe",
25                "0",
26                "-i",
27                list_path.to_str().unwrap(),
28                "-c",
29                "copy",
30                self.output_path().to_str().unwrap(),
31            ])
32            .status()?;
33
34        if status.success() {
35            debug!("ffmpeg merged parts successfully");
36            Ok(())
37        } else {
38            error!("ffmpeg returned non‑zero status {status}");
39            Err(
40                BatchModeTtsError::FfmpegMergeError { status }
41            )
42        }
43    }
44}