Skip to main content

gproxy_protocol/wire/openai/realtime/
audio.rs

1//! Native Realtime wire DTOs. Source definitions are cited on each object.
2//! Verified with Realtime.md and openai-python snapshot
3//! e12b81d3bbf644ec7045e152d69bc4b68d69cd48 (2026-09-13).
4//! https://github.com/openai/openai-python/tree/e12b81d3bbf644ec7045e152d69bc4b68d69cd48/src/openai/types/realtime
5use super::wire::present_nullable;
6use super::{AudioTranscription, NoiseReductionType};
7use crate::Rest;
8use serde::{Deserialize, Serialize};
9
10/// Source: `openai/types/realtime/realtime_audio_config.py`, `RealtimeAudioConfig`.
11#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
12#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
13#[derive(gproxy_protocol_macros::DeclaredFields)]
14#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
15pub struct RealtimeAudioConfig {
16    #[serde(
17        default,
18        deserialize_with = "present_nullable",
19        skip_serializing_if = "Option::is_none"
20    )]
21    pub input: Option<Option<RealtimeAudioConfigInput>>,
22    #[serde(
23        default,
24        deserialize_with = "present_nullable",
25        skip_serializing_if = "Option::is_none"
26    )]
27    pub output: Option<Option<RealtimeAudioConfigOutput>>,
28    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
29    pub rest: Rest,
30}
31
32/// Source: `openai/types/realtime/realtime_audio_config_input.py`, `RealtimeAudioConfigInput`.
33#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
34#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
35#[derive(gproxy_protocol_macros::DeclaredFields)]
36#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
37pub struct RealtimeAudioConfigInput {
38    #[serde(
39        default,
40        deserialize_with = "present_nullable",
41        skip_serializing_if = "Option::is_none"
42    )]
43    pub format: Option<Option<RealtimeAudioFormats>>,
44    #[serde(
45        default,
46        deserialize_with = "present_nullable",
47        skip_serializing_if = "Option::is_none"
48    )]
49    pub noise_reduction: Option<Option<RealtimeAudioConfigInputNoiseReduction>>,
50    #[serde(
51        default,
52        deserialize_with = "present_nullable",
53        skip_serializing_if = "Option::is_none"
54    )]
55    pub transcription: Option<Option<AudioTranscription>>,
56    #[serde(
57        default,
58        deserialize_with = "present_nullable",
59        skip_serializing_if = "Option::is_none"
60    )]
61    pub turn_detection: Option<Option<RealtimeAudioInputTurnDetection>>,
62    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
63    pub rest: Rest,
64}
65
66/// Source: `openai/types/realtime/realtime_audio_config_output.py`, `RealtimeAudioConfigOutput`.
67#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
68#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
69#[derive(gproxy_protocol_macros::DeclaredFields)]
70#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
71pub struct RealtimeAudioConfigOutput {
72    #[serde(
73        default,
74        deserialize_with = "present_nullable",
75        skip_serializing_if = "Option::is_none"
76    )]
77    pub format: Option<Option<RealtimeAudioFormats>>,
78    #[serde(
79        default,
80        deserialize_with = "present_nullable",
81        skip_serializing_if = "Option::is_none"
82    )]
83    pub speed: Option<Option<serde_json::Number>>,
84    #[serde(
85        default,
86        deserialize_with = "present_nullable",
87        skip_serializing_if = "Option::is_none"
88    )]
89    pub voice: Option<Option<RealtimeAudioConfigOutputVoice>>,
90    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
91    pub rest: Rest,
92}
93
94/// Source: `openai/types/realtime/realtime_audio_formats.py`, `RealtimeAudioFormats`.
95#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
96#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
97#[serde(untagged)]
98#[derive(gproxy_protocol_macros::DeclaredFields)]
99#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
100pub enum RealtimeAudioFormats {
101    RealtimeAudioFormatsAudioPCM(RealtimeAudioFormatsAudioPCM),
102    RealtimeAudioFormatsAudioPCMU(RealtimeAudioFormatsAudioPCMU),
103    RealtimeAudioFormatsAudioPCMA(RealtimeAudioFormatsAudioPCMA),
104}
105
106/// Source: `openai/types/realtime/realtime_audio_config_input.py`, `NoiseReduction`.
107#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
108#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
109#[derive(gproxy_protocol_macros::DeclaredFields)]
110#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
111pub struct RealtimeAudioConfigInputNoiseReduction {
112    #[serde(rename = "type")]
113    #[serde(
114        default,
115        deserialize_with = "present_nullable",
116        skip_serializing_if = "Option::is_none"
117    )]
118    pub type_: Option<Option<NoiseReductionType>>,
119    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
120    pub rest: Rest,
121}
122
123/// Source: `openai/types/realtime/realtime_audio_input_turn_detection.py`, `RealtimeAudioInputTurnDetection`.
124#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
125#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
126#[serde(untagged)]
127#[derive(gproxy_protocol_macros::DeclaredFields)]
128#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
129pub enum RealtimeAudioInputTurnDetection {
130    RealtimeAudioInputTurnDetectionServerVad(RealtimeAudioInputTurnDetectionServerVad),
131    RealtimeAudioInputTurnDetectionSemanticVad(RealtimeAudioInputTurnDetectionSemanticVad),
132    Variant3(()),
133}
134
135/// Source: `openai/types/realtime/realtime_audio_config_output.py`, `Voice`.
136#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
137#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
138#[serde(untagged)]
139#[derive(gproxy_protocol_macros::DeclaredFields)]
140#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
141pub enum RealtimeAudioConfigOutputVoice {
142    Text(String),
143    RealtimeAudioConfigOutputVoiceID(RealtimeAudioConfigOutputVoiceID),
144}
145
146/// Source: `openai/types/realtime/realtime_audio_formats.py`, `AudioPCM`.
147#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
148#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
149#[derive(gproxy_protocol_macros::DeclaredFields)]
150#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
151pub struct RealtimeAudioFormatsAudioPCM {
152    #[serde(
153        default,
154        deserialize_with = "present_nullable",
155        skip_serializing_if = "Option::is_none"
156    )]
157    pub rate: Option<Option<RealtimeAudioFormatsAudioPCMRate>>,
158    #[serde(rename = "type")]
159    #[serde(
160        default,
161        deserialize_with = "present_nullable",
162        skip_serializing_if = "Option::is_none"
163    )]
164    pub type_: Option<Option<RealtimeAudioFormatsAudioPCMType>>,
165    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
166    pub rest: Rest,
167}
168
169/// Source: `openai/types/realtime/realtime_audio_formats.py`, `AudioPCMU`.
170#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
171#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
172#[derive(gproxy_protocol_macros::DeclaredFields)]
173#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
174pub struct RealtimeAudioFormatsAudioPCMU {
175    #[serde(rename = "type")]
176    #[serde(
177        default,
178        deserialize_with = "present_nullable",
179        skip_serializing_if = "Option::is_none"
180    )]
181    pub type_: Option<Option<RealtimeAudioFormatsAudioPCMUType>>,
182    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
183    pub rest: Rest,
184}
185
186/// Source: `openai/types/realtime/realtime_audio_formats.py`, `AudioPCMA`.
187#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
188#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
189#[derive(gproxy_protocol_macros::DeclaredFields)]
190#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
191pub struct RealtimeAudioFormatsAudioPCMA {
192    #[serde(rename = "type")]
193    #[serde(
194        default,
195        deserialize_with = "present_nullable",
196        skip_serializing_if = "Option::is_none"
197    )]
198    pub type_: Option<Option<RealtimeAudioFormatsAudioPCMAType>>,
199    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
200    pub rest: Rest,
201}
202
203/// Source: `openai/types/realtime/realtime_audio_input_turn_detection.py`, `ServerVad`.
204#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
205#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
206#[derive(gproxy_protocol_macros::DeclaredFields)]
207#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
208pub struct RealtimeAudioInputTurnDetectionServerVad {
209    #[serde(rename = "type")]
210    pub type_: RealtimeAudioInputTurnDetectionServerVadType,
211    #[serde(
212        default,
213        deserialize_with = "present_nullable",
214        skip_serializing_if = "Option::is_none"
215    )]
216    pub create_response: Option<Option<bool>>,
217    #[serde(
218        default,
219        deserialize_with = "present_nullable",
220        skip_serializing_if = "Option::is_none"
221    )]
222    pub idle_timeout_ms: Option<Option<i64>>,
223    #[serde(
224        default,
225        deserialize_with = "present_nullable",
226        skip_serializing_if = "Option::is_none"
227    )]
228    pub interrupt_response: Option<Option<bool>>,
229    #[serde(
230        default,
231        deserialize_with = "present_nullable",
232        skip_serializing_if = "Option::is_none"
233    )]
234    pub prefix_padding_ms: Option<Option<i64>>,
235    #[serde(
236        default,
237        deserialize_with = "present_nullable",
238        skip_serializing_if = "Option::is_none"
239    )]
240    pub silence_duration_ms: Option<Option<i64>>,
241    #[serde(
242        default,
243        deserialize_with = "present_nullable",
244        skip_serializing_if = "Option::is_none"
245    )]
246    pub threshold: Option<Option<serde_json::Number>>,
247    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
248    pub rest: Rest,
249}
250
251/// Source: `openai/types/realtime/realtime_audio_input_turn_detection.py`, `SemanticVad`.
252#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
253#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
254#[derive(gproxy_protocol_macros::DeclaredFields)]
255#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
256pub struct RealtimeAudioInputTurnDetectionSemanticVad {
257    #[serde(rename = "type")]
258    pub type_: RealtimeAudioInputTurnDetectionSemanticVadType,
259    #[serde(
260        default,
261        deserialize_with = "present_nullable",
262        skip_serializing_if = "Option::is_none"
263    )]
264    pub create_response: Option<Option<bool>>,
265    #[serde(
266        default,
267        deserialize_with = "present_nullable",
268        skip_serializing_if = "Option::is_none"
269    )]
270    pub eagerness: Option<Option<RealtimeAudioInputTurnDetectionSemanticVadEagerness>>,
271    #[serde(
272        default,
273        deserialize_with = "present_nullable",
274        skip_serializing_if = "Option::is_none"
275    )]
276    pub interrupt_response: Option<Option<bool>>,
277    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
278    pub rest: Rest,
279}
280
281/// Source: `openai/types/realtime/realtime_audio_config_output.py`, `VoiceID`.
282#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
283#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
284#[derive(gproxy_protocol_macros::DeclaredFields)]
285#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
286pub struct RealtimeAudioConfigOutputVoiceID {
287    pub id: String,
288    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
289    pub rest: Rest,
290}
291
292/// A numeric literal validated through scalar conversion; object routing remains derived.
293#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
294#[serde(try_from = "i64", into = "i64")]
295#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
296#[derive(gproxy_protocol_macros::DeclaredFields)]
297#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
298pub enum RealtimeAudioFormatsAudioPCMRate {
299    Value24000,
300}
301impl TryFrom<i64> for RealtimeAudioFormatsAudioPCMRate {
302    type Error = &'static str;
303    fn try_from(value: i64) -> Result<Self, Self::Error> {
304        if value == 24000 {
305            Ok(Self::Value24000)
306        } else {
307            Err("expected 24000")
308        }
309    }
310}
311impl From<RealtimeAudioFormatsAudioPCMRate> for i64 {
312    fn from(_: RealtimeAudioFormatsAudioPCMRate) -> Self {
313        24000
314    }
315}
316
317#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
318#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
319#[derive(gproxy_protocol_macros::DeclaredFields)]
320#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
321pub enum RealtimeAudioFormatsAudioPCMType {
322    #[serde(rename = "audio/pcm")]
323    AudioPcm,
324}
325
326#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
327#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
328#[derive(gproxy_protocol_macros::DeclaredFields)]
329#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
330pub enum RealtimeAudioFormatsAudioPCMUType {
331    #[serde(rename = "audio/pcmu")]
332    AudioPcmu,
333}
334
335#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
336#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
337#[derive(gproxy_protocol_macros::DeclaredFields)]
338#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
339pub enum RealtimeAudioFormatsAudioPCMAType {
340    #[serde(rename = "audio/pcma")]
341    AudioPcma,
342}
343
344#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
345#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
346#[derive(gproxy_protocol_macros::DeclaredFields)]
347#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
348pub enum RealtimeAudioInputTurnDetectionServerVadType {
349    #[serde(rename = "server_vad")]
350    ServerVad,
351}
352
353#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
354#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
355#[derive(gproxy_protocol_macros::DeclaredFields)]
356#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
357pub enum RealtimeAudioInputTurnDetectionSemanticVadType {
358    #[serde(rename = "semantic_vad")]
359    SemanticVad,
360}
361
362#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
363#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
364#[derive(gproxy_protocol_macros::DeclaredFields)]
365#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
366pub enum RealtimeAudioInputTurnDetectionSemanticVadEagerness {
367    #[serde(rename = "low")]
368    Low,
369    #[serde(rename = "medium")]
370    Medium,
371    #[serde(rename = "high")]
372    High,
373    #[serde(rename = "auto")]
374    Auto,
375}