batch_mode_tts/
batch_mode_tts.rs

1crate::ix!();
2
3/// ---------------------------------------------------------------------------
4/// Chunk‑aware TTS job & builder
5/// ---------------------------------------------------------------------------
6#[derive(Getters, Builder, Debug, Clone)]
7#[builder(name = "BatchModeTtsJobBuilder", pattern = "owned")]
8#[getset(get = "pub")]
9pub struct BatchModeTtsJob {
10    /// Source UTF‑8 text file.
11    input_path: PathBuf,
12    /// Final destination audio file.
13    output_path: PathBuf,
14
15    // Optional staging directory; defaults to `<output_path>.parts`
16    #[builder(setter(strip_option), default)]
17    work_dir: Option<PathBuf>,
18
19    // Maximum characters per TTS request (<=4096 by OpenAI spec).
20    #[builder(default = "3500")]
21    chunk_chars: usize,
22
23    #[builder(default = "SpeechModel::Tts1")]
24    model: SpeechModel,
25    #[builder(default = "Voice::Sage")]
26    voice: Voice,
27    #[builder(default = "SpeechResponseFormat::Mp3")]
28    response_format: SpeechResponseFormat,
29    #[builder(default = "1.0")]
30    speed: f32,
31}
32
33impl BatchModeTtsJob {
34
35    pub fn ext_for_format(fmt: SpeechResponseFormat) -> &'static str {
36        match fmt {
37            SpeechResponseFormat::Mp3 => "mp3",
38            SpeechResponseFormat::Opus => "ogg",
39            SpeechResponseFormat::Aac => "aac",
40            SpeechResponseFormat::Flac => "flac",
41            SpeechResponseFormat::Pcm => "pcm",
42            SpeechResponseFormat::Wav => "wav",
43            //_ => "bin",
44        }
45    }
46}