Skip to main content

openai_types/audio/
request.rs

1// Manual: audio request types with builder patterns.
2
3use serde::Serialize;
4
5use super::enums::{AudioResponseFormat, AudioVoice, SpeechResponseFormat};
6
7/// Parameters for audio transcription (multipart upload).
8#[derive(Debug)]
9pub struct TranscriptionParams {
10    pub file: Vec<u8>,
11    pub filename: String,
12    pub model: String,
13    pub language: Option<String>,
14    pub prompt: Option<String>,
15    pub response_format: Option<AudioResponseFormat>,
16    pub temperature: Option<f64>,
17}
18
19impl TranscriptionParams {
20    pub fn new(file: Vec<u8>, filename: impl Into<String>, model: impl Into<String>) -> Self {
21        Self {
22            file,
23            filename: filename.into(),
24            model: model.into(),
25            language: None,
26            prompt: None,
27            response_format: None,
28            temperature: None,
29        }
30    }
31}
32
33/// Parameters for audio translation (multipart upload).
34#[derive(Debug)]
35pub struct TranslationParams {
36    pub file: Vec<u8>,
37    pub filename: String,
38    pub model: String,
39    pub prompt: Option<String>,
40    pub response_format: Option<AudioResponseFormat>,
41    pub temperature: Option<f64>,
42}
43
44impl TranslationParams {
45    pub fn new(file: Vec<u8>, filename: impl Into<String>, model: impl Into<String>) -> Self {
46        Self {
47            file,
48            filename: filename.into(),
49            model: model.into(),
50            prompt: None,
51            response_format: None,
52            temperature: None,
53        }
54    }
55}
56
57/// Request body for `POST /audio/speech`.
58#[derive(Debug, Clone, Serialize)]
59pub struct SpeechRequest {
60    /// Text to convert to audio.
61    pub input: String,
62    /// TTS model (e.g. "tts-1", "tts-1-hd").
63    pub model: String,
64    /// Voice for audio output.
65    pub voice: AudioVoice,
66    /// Audio format.
67    #[serde(skip_serializing_if = "Option::is_none")]
68    pub response_format: Option<SpeechResponseFormat>,
69    /// Playback speed (0.25 to 4.0).
70    #[serde(skip_serializing_if = "Option::is_none")]
71    pub speed: Option<f64>,
72}
73
74impl SpeechRequest {
75    pub fn new(input: impl Into<String>, model: impl Into<String>, voice: AudioVoice) -> Self {
76        Self {
77            input: input.into(),
78            model: model.into(),
79            voice,
80            response_format: None,
81            speed: None,
82        }
83    }
84}