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