Skip to main content

openai_tools/realtime/
audio.rs

1//! Audio types for the Realtime API.
2
3use serde::{Deserialize, Serialize};
4
5/// Audio formats supported by the Realtime API.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
7#[serde(rename_all = "snake_case")]
8#[non_exhaustive]
9pub enum AudioFormat {
10    /// PCM 16-bit linear encoding (24kHz, mono)
11    #[default]
12    Pcm16,
13    /// G.711 mu-law encoding
14    G711Ulaw,
15    /// G.711 A-law encoding
16    G711Alaw,
17}
18
19/// Voice options for text-to-speech output.
20#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
21#[serde(rename_all = "lowercase")]
22#[non_exhaustive]
23pub enum Voice {
24    #[default]
25    Alloy,
26    Ash,
27    Ballad,
28    Coral,
29    Echo,
30    Sage,
31    Shimmer,
32    Verse,
33}
34
35/// Transcription model options for input audio.
36#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
37#[non_exhaustive]
38pub enum TranscriptionModel {
39    #[serde(rename = "whisper-1")]
40    #[default]
41    Whisper1,
42}
43
44/// Input audio transcription configuration.
45#[derive(Debug, Clone, Default, Serialize, Deserialize)]
46pub struct InputAudioTranscription {
47    /// The transcription model to use.
48    #[serde(skip_serializing_if = "Option::is_none")]
49    pub model: Option<TranscriptionModel>,
50
51    /// Language hint for transcription (ISO-639-1 code).
52    #[serde(skip_serializing_if = "Option::is_none")]
53    pub language: Option<String>,
54
55    /// Optional prompt to guide transcription.
56    #[serde(skip_serializing_if = "Option::is_none")]
57    pub prompt: Option<String>,
58}
59
60impl InputAudioTranscription {
61    /// Create a new transcription configuration with the specified model.
62    pub fn new(model: TranscriptionModel) -> Self {
63        Self { model: Some(model), language: None, prompt: None }
64    }
65
66    /// Set the language hint.
67    pub fn with_language(mut self, language: impl Into<String>) -> Self {
68        self.language = Some(language.into());
69        self
70    }
71
72    /// Set the transcription prompt.
73    pub fn with_prompt(mut self, prompt: impl Into<String>) -> Self {
74        self.prompt = Some(prompt.into());
75        self
76    }
77}
78
79/// Input audio noise reduction configuration.
80#[derive(Debug, Clone, Serialize, Deserialize)]
81pub struct InputAudioNoiseReduction {
82    /// Type of noise reduction to apply.
83    #[serde(rename = "type")]
84    pub noise_type: NoiseReductionType,
85}
86
87/// Noise reduction type options.
88#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
89#[serde(rename_all = "snake_case")]
90#[non_exhaustive]
91pub enum NoiseReductionType {
92    /// Optimized for near-field audio (close microphone).
93    NearField,
94    /// Optimized for far-field audio (distant microphone).
95    FarField,
96}