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