Skip to main content

openai_types/audio/
_gen.rs

1// AUTO-GENERATED by py2rust — do not edit.
2// Re-generate: python3 scripts/py2rust.py sync <python_dir> <rust_dir>
3// Domain: audio
4#![allow(unused_imports)]
5
6use serde::{Deserialize, Serialize};
7use super::*;
8
9#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
10#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
11#[non_exhaustive]
12pub enum SpeechCreateParamsResponseFormat {
13    #[serde(rename = "mp3")]
14    Mp3,
15    #[serde(rename = "opus")]
16    Opus,
17    #[serde(rename = "aac")]
18    Aac,
19    #[serde(rename = "flac")]
20    Flac,
21    #[serde(rename = "wav")]
22    Wav,
23    #[serde(rename = "pcm")]
24    Pcm,
25}
26
27#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
28#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
29#[non_exhaustive]
30pub enum SpeechCreateParamsStreamFormat {
31    #[serde(rename = "sse")]
32    Sse,
33    #[serde(rename = "audio")]
34    Audio,
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
39pub struct SpeechCreateParams {
40    /// The text to generate audio for. The maximum length is 4096 characters.
41    pub input: String,
42    /// One of the available [TTS models](https://platform.openai.com/docs/models#tts):
43    pub model: String,
44    /// The voice to use when generating the audio.
45    pub voice: Voice,
46    /// Control the voice of your generated audio with additional instructions.
47    #[serde(skip_serializing_if = "Option::is_none", default)]
48    pub instructions: Option<String>,
49    /// The format to audio in.
50    #[serde(skip_serializing_if = "Option::is_none", default)]
51    pub response_format: Option<SpeechCreateParamsResponseFormat>,
52    /// The speed of the generated audio.
53    #[serde(skip_serializing_if = "Option::is_none", default)]
54    pub speed: Option<f64>,
55    /// The format to stream the audio in.
56    #[serde(skip_serializing_if = "Option::is_none", default)]
57    pub stream_format: Option<SpeechCreateParamsStreamFormat>,
58}
59
60/// Custom voice reference.
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
63pub struct VoiceID {
64    /// The custom voice ID, e.g. `voice_1234`.
65    pub id: String,
66}
67
68#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
69#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
70#[non_exhaustive]
71pub enum Voice {
72    Alloy,
73    Ash,
74    Ballad,
75    Coral,
76    Echo,
77    Sage,
78    Shimmer,
79    Verse,
80    Marin,
81    Cedar,
82}
83
84#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
85#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
86#[non_exhaustive]
87pub enum SpeechModel {
88    #[serde(rename = "tts-1")]
89    Tts1,
90    #[serde(rename = "tts-1-hd")]
91    Tts1Hd,
92    #[serde(rename = "gpt-4o-mini-tts")]
93    Gpt4oMiniTts,
94    #[serde(rename = "gpt-4o-mini-tts-2025-12-15")]
95    Gpt4oMiniTts20251215,
96}
97
98#[derive(Debug, Clone, Serialize, Deserialize)]
99#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
100pub struct Logprob {
101    /// The token in the transcription.
102    #[serde(skip_serializing_if = "Option::is_none", default)]
103    pub token: Option<String>,
104    /// The bytes of the token.
105    #[serde(skip_serializing_if = "Option::is_none", default)]
106    pub bytes: Option<Vec<f64>>,
107    /// The log probability of the token.
108    #[serde(skip_serializing_if = "Option::is_none", default)]
109    pub logprob: Option<f64>,
110}
111
112/// Details about the input tokens billed for this request.
113#[derive(Debug, Clone, Serialize, Deserialize)]
114#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
115pub struct UsageTokensInputTokenDetails {
116    /// Number of audio tokens billed for this request.
117    #[serde(skip_serializing_if = "Option::is_none", default)]
118    pub audio_tokens: Option<i64>,
119    /// Number of text tokens billed for this request.
120    #[serde(skip_serializing_if = "Option::is_none", default)]
121    pub text_tokens: Option<i64>,
122}
123
124/// Usage statistics for models billed by token usage.
125#[derive(Debug, Clone, Serialize, Deserialize)]
126#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
127pub struct UsageTokens {
128    /// Number of input tokens billed for this request.
129    pub input_tokens: i64,
130    /// Number of output tokens generated.
131    pub output_tokens: i64,
132    /// Total number of tokens used (input + output).
133    pub total_tokens: i64,
134    /// The type of the usage object. Always `tokens` for this variant.
135    #[serde(rename = "type")]
136    pub type_: String,
137    /// Details about the input tokens billed for this request.
138    #[serde(skip_serializing_if = "Option::is_none", default)]
139    pub input_token_details: Option<UsageTokensInputTokenDetails>,
140}
141
142/// Usage statistics for models billed by audio input duration.
143#[derive(Debug, Clone, Serialize, Deserialize)]
144#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
145pub struct UsageDuration {
146    /// Duration of the input audio in seconds.
147    pub seconds: f64,
148    /// The type of the usage object. Always `duration` for this variant.
149    #[serde(rename = "type")]
150    pub type_: String,
151}
152
153pub type Usage = serde_json::Value;
154
155#[derive(Debug, Clone, Serialize, Deserialize)]
156#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
157pub struct TranscriptionCreateParamsBase {
158    /// The audio file object (not file name) to transcribe, in one of these formats:
159    pub file: serde_json::Value,
160    /// ID of the model to use.
161    pub model: String,
162    /// Controls how the audio is cut into chunks.
163    #[serde(skip_serializing_if = "Option::is_none", default)]
164    pub chunking_strategy: Option<ChunkingStrategy>,
165    /// Additional information to include in the transcription response. `logprobs` will
166    #[serde(skip_serializing_if = "Option::is_none", default)]
167    pub include: Option<Vec<TranscriptionInclude>>,
168    /// Optional list of speaker names that correspond to the audio samples provided in
169    #[serde(skip_serializing_if = "Option::is_none", default)]
170    pub known_speaker_names: Option<serde_json::Value>,
171    /// Optional list of audio samples (as
172    #[serde(skip_serializing_if = "Option::is_none", default)]
173    pub known_speaker_references: Option<serde_json::Value>,
174    /// The language of the input audio.
175    #[serde(skip_serializing_if = "Option::is_none", default)]
176    pub language: Option<String>,
177    /// An optional text to guide the model's style or continue a previous audio
178    #[serde(skip_serializing_if = "Option::is_none", default)]
179    pub prompt: Option<String>,
180    /// The format of the output, in one of these options: `json`, `text`, `srt`,
181    #[serde(skip_serializing_if = "Option::is_none", default)]
182    pub response_format: Option<AudioResponseFormat>,
183    /// The sampling temperature, between 0 and 1.
184    #[serde(skip_serializing_if = "Option::is_none", default)]
185    pub temperature: Option<f64>,
186    /// The timestamp granularities to populate for this transcription.
187    #[serde(skip_serializing_if = "Option::is_none", default)]
188    pub timestamp_granularities: Option<Vec<serde_json::Value>>,
189}
190
191#[derive(Debug, Clone, Serialize, Deserialize)]
192#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
193pub struct ChunkingStrategyVadConfig {
194    /// Must be set to `server_vad` to enable manual chunking using server side VAD.
195    #[serde(rename = "type")]
196    pub type_: String,
197    /// Amount of audio to include before the VAD detected speech (in milliseconds).
198    #[serde(skip_serializing_if = "Option::is_none", default)]
199    pub prefix_padding_ms: Option<i64>,
200    /// Duration of silence to detect speech stop (in milliseconds). With shorter values
201    #[serde(skip_serializing_if = "Option::is_none", default)]
202    pub silence_duration_ms: Option<i64>,
203    /// Sensitivity threshold (0.0 to 1.0) for voice activity detection.
204    #[serde(skip_serializing_if = "Option::is_none", default)]
205    pub threshold: Option<f64>,
206}
207
208#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
209#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
210#[non_exhaustive]
211pub enum ChunkingStrategy {
212    Auto,
213}
214
215pub type TranscriptionCreateParams = serde_json::Value;
216
217pub type TranscriptionCreateResponse = serde_json::Value;
218
219/// Represents a diarized transcription response returned by the model, including the combined transcript and speaker-segment annotations.
220#[derive(Debug, Clone, Serialize, Deserialize)]
221#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
222pub struct TranscriptionDiarized {
223    /// Duration of the input audio in seconds.
224    pub duration: f64,
225    /// Segments of the transcript annotated with timestamps and speaker labels.
226    pub segments: Vec<TranscriptionDiarizedSegment>,
227    /// The type of task that was run. Always `transcribe`.
228    pub task: String,
229    /// The concatenated transcript text for the entire audio input.
230    pub text: String,
231    /// Token or duration usage statistics for the request.
232    #[serde(skip_serializing_if = "Option::is_none", default)]
233    pub usage: Option<Usage>,
234}
235
236/// A segment of diarized transcript text with speaker metadata.
237#[derive(Debug, Clone, Serialize, Deserialize)]
238#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
239pub struct TranscriptionDiarizedSegment {
240    /// Unique identifier for the segment.
241    pub id: String,
242    /// End timestamp of the segment in seconds.
243    pub end: f64,
244    /// Speaker label for this segment.
245    pub speaker: String,
246    /// Start timestamp of the segment in seconds.
247    pub start: f64,
248    /// Transcript text for this segment.
249    pub text: String,
250    /// The type of the segment. Always `transcript.text.segment`.
251    #[serde(rename = "type")]
252    pub type_: String,
253}
254
255#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
256#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
257#[non_exhaustive]
258pub enum TranscriptionInclude {
259    #[serde(rename = "logprobs")]
260    Logprobs,
261}
262
263#[derive(Debug, Clone, Serialize, Deserialize)]
264#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
265pub struct TranscriptionSegment {
266    /// Unique identifier of the segment.
267    pub id: i64,
268    /// Average logprob of the segment.
269    pub avg_logprob: f64,
270    /// Compression ratio of the segment.
271    pub compression_ratio: f64,
272    /// End time of the segment in seconds.
273    pub end: f64,
274    /// Probability of no speech in the segment.
275    pub no_speech_prob: f64,
276    /// Seek offset of the segment.
277    pub seek: i64,
278    /// Start time of the segment in seconds.
279    pub start: f64,
280    /// Temperature parameter used for generating the segment.
281    pub temperature: f64,
282    /// Text content of the segment.
283    pub text: String,
284    /// Array of token IDs for the text content.
285    pub tokens: Vec<i64>,
286}
287
288pub type TranscriptionStreamEvent = serde_json::Value;
289
290/// Emitted when there is an additional text delta.
291#[derive(Debug, Clone, Serialize, Deserialize)]
292#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
293pub struct TranscriptionTextDeltaEvent {
294    /// The text delta that was additionally transcribed.
295    pub delta: String,
296    /// The type of the event. Always `transcript.text.delta`.
297    #[serde(rename = "type")]
298    pub type_: String,
299    /// The log probabilities of the delta.
300    #[serde(skip_serializing_if = "Option::is_none", default)]
301    pub logprobs: Option<Vec<Logprob>>,
302    /// Identifier of the diarized segment that this delta belongs to.
303    #[serde(skip_serializing_if = "Option::is_none", default)]
304    pub segment_id: Option<String>,
305}
306
307/// Details about the input tokens billed for this request.
308#[derive(Debug, Clone, Serialize, Deserialize)]
309#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
310pub struct UsageInputTokenDetails {
311    /// Number of audio tokens billed for this request.
312    #[serde(skip_serializing_if = "Option::is_none", default)]
313    pub audio_tokens: Option<i64>,
314    /// Number of text tokens billed for this request.
315    #[serde(skip_serializing_if = "Option::is_none", default)]
316    pub text_tokens: Option<i64>,
317}
318
319/// Emitted when the transcription is complete.
320#[derive(Debug, Clone, Serialize, Deserialize)]
321#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
322pub struct TranscriptionTextDoneEvent {
323    /// The text that was transcribed.
324    pub text: String,
325    /// The type of the event. Always `transcript.text.done`.
326    #[serde(rename = "type")]
327    pub type_: String,
328    /// The log probabilities of the individual tokens in the transcription.
329    #[serde(skip_serializing_if = "Option::is_none", default)]
330    pub logprobs: Option<Vec<Logprob>>,
331    /// Usage statistics for models billed by token usage.
332    #[serde(skip_serializing_if = "Option::is_none", default)]
333    pub usage: Option<Usage>,
334}
335
336/// Emitted when a diarized transcription returns a completed segment with speaker information. Only emitted when you [create a transcription](https://platform.openai.com/docs/api-reference/audio/create-transcription) with `stream` set to `true` and `response_format` set to `diarized_json`.
337#[derive(Debug, Clone, Serialize, Deserialize)]
338#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
339pub struct TranscriptionTextSegmentEvent {
340    /// Unique identifier for the segment.
341    pub id: String,
342    /// End timestamp of the segment in seconds.
343    pub end: f64,
344    /// Speaker label for this segment.
345    pub speaker: String,
346    /// Start timestamp of the segment in seconds.
347    pub start: f64,
348    /// Transcript text for this segment.
349    pub text: String,
350    /// The type of the event. Always `transcript.text.segment`.
351    #[serde(rename = "type")]
352    pub type_: String,
353}
354
355/// Represents a verbose json transcription response returned by model, based on the provided input.
356#[derive(Debug, Clone, Serialize, Deserialize)]
357#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
358pub struct TranscriptionVerbose {
359    /// The duration of the input audio.
360    pub duration: f64,
361    /// The language of the input audio.
362    pub language: String,
363    /// The transcribed text.
364    pub text: String,
365    /// Segments of the transcribed text and their corresponding details.
366    #[serde(skip_serializing_if = "Option::is_none", default)]
367    pub segments: Option<Vec<TranscriptionSegment>>,
368    /// Usage statistics for models billed by audio input duration.
369    #[serde(skip_serializing_if = "Option::is_none", default)]
370    pub usage: Option<Usage>,
371    /// Extracted words and their corresponding timestamps.
372    #[serde(skip_serializing_if = "Option::is_none", default)]
373    pub words: Option<Vec<TranscriptionWord>>,
374}
375
376#[derive(Debug, Clone, Serialize, Deserialize)]
377#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
378pub struct TranscriptionWord {
379    /// End time of the word in seconds.
380    pub end: f64,
381    /// Start time of the word in seconds.
382    pub start: f64,
383    /// The text content of the word.
384    pub word: String,
385}
386
387#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
388#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
389#[non_exhaustive]
390pub enum TranslationCreateParamsResponseFormat {
391    #[serde(rename = "json")]
392    Json,
393    #[serde(rename = "text")]
394    Text,
395    #[serde(rename = "srt")]
396    Srt,
397    #[serde(rename = "verbose_json")]
398    VerboseJson,
399    #[serde(rename = "vtt")]
400    Vtt,
401}
402
403#[derive(Debug, Clone, Serialize, Deserialize)]
404#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
405pub struct TranslationCreateParams {
406    /// The audio file object (not file name) translate, in one of these formats: flac,
407    pub file: serde_json::Value,
408    /// ID of the model to use.
409    pub model: String,
410    /// An optional text to guide the model's style or continue a previous audio
411    #[serde(skip_serializing_if = "Option::is_none", default)]
412    pub prompt: Option<String>,
413    /// The format of the output, in one of these options: `json`, `text`, `srt`,
414    #[serde(skip_serializing_if = "Option::is_none", default)]
415    pub response_format: Option<TranslationCreateParamsResponseFormat>,
416    /// The sampling temperature, between 0 and 1.
417    #[serde(skip_serializing_if = "Option::is_none", default)]
418    pub temperature: Option<f64>,
419}
420
421pub type TranslationCreateResponse = serde_json::Value;
422
423#[derive(Debug, Clone, Serialize, Deserialize)]
424#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
425pub struct TranslationVerbose {
426    /// The duration of the input audio.
427    pub duration: f64,
428    /// The language of the output translation (always `english`).
429    pub language: String,
430    /// The translated text.
431    pub text: String,
432    /// Segments of the translated text and their corresponding details.
433    #[serde(skip_serializing_if = "Option::is_none", default)]
434    pub segments: Option<Vec<TranscriptionSegment>>,
435}
436
437#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
438#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
439#[non_exhaustive]
440pub enum AudioModel {
441    #[serde(rename = "whisper-1")]
442    Whisper1,
443    #[serde(rename = "gpt-4o-transcribe")]
444    Gpt4oTranscribe,
445    #[serde(rename = "gpt-4o-mini-transcribe")]
446    Gpt4oMiniTranscribe,
447    #[serde(rename = "gpt-4o-mini-transcribe-2025-12-15")]
448    Gpt4oMiniTranscribe20251215,
449    #[serde(rename = "gpt-4o-transcribe-diarize")]
450    Gpt4oTranscribeDiarize,
451}