openai-client-base 0.13.0

Auto-generated Rust client for the OpenAI API
/*
 * OpenAI API
 *
 * The OpenAI REST API. Please see https://platform.openai.com/docs/api-reference for more details.
 *
 * The version of the OpenAPI document: 2.3.0
 *
 * Generated by: https://openapi-generator.tech
 */

use crate::models;
use serde::{Deserialize, Serialize};

/// RealtimeTranslationServerEventSessionOutputAudioDelta : Returned when translated output audio is available. Output audio deltas are 200 ms frames of PCM16 audio.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct RealtimeTranslationServerEventSessionOutputAudioDelta {
    /// The unique ID of the server event.
    #[serde(rename = "event_id")]
    pub event_id: String,
    /// The event type, must be `session.output_audio.delta`.
    #[serde(rename = "type")]
    pub r#type: Type,
    /// Base64-encoded translated audio data.
    #[serde(rename = "delta")]
    pub delta: String,
    /// Sample rate of the audio delta.
    #[serde(rename = "sample_rate", skip_serializing_if = "Option::is_none")]
    pub sample_rate: Option<i32>,
    /// Number of audio channels.
    #[serde(rename = "channels", skip_serializing_if = "Option::is_none")]
    pub channels: Option<i32>,
    /// Audio encoding for `delta`.
    #[serde(rename = "format", skip_serializing_if = "Option::is_none")]
    pub format: Option<Format>,
    /// Timing metadata for stream alignment, derived from the translation frame when available. Treat `elapsed_ms` as alignment metadata, not a unique event identifier.
    #[serde(
        rename = "elapsed_ms",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub elapsed_ms: Option<Option<i32>>,
}

impl RealtimeTranslationServerEventSessionOutputAudioDelta {
    /// Returned when translated output audio is available. Output audio deltas are 200 ms frames of PCM16 audio.
    pub fn new(
        event_id: String,
        r#type: Type,
        delta: String,
    ) -> RealtimeTranslationServerEventSessionOutputAudioDelta {
        RealtimeTranslationServerEventSessionOutputAudioDelta {
            event_id,
            r#type,
            delta,
            sample_rate: None,
            channels: None,
            format: None,
            elapsed_ms: None,
        }
    }
}
/// The event type, must be `session.output_audio.delta`.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Type {
    #[serde(rename = "session.output_audio.delta")]
    SessionOutputAudioDelta,
}

impl Default for Type {
    fn default() -> Type {
        Self::SessionOutputAudioDelta
    }
}
/// Audio encoding for `delta`.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Format {
    #[serde(rename = "pcm16")]
    Pcm16,
}

impl Default for Format {
    fn default() -> Format {
        Self::Pcm16
    }
}

impl std::fmt::Display for RealtimeTranslationServerEventSessionOutputAudioDelta {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match serde_json::to_string(self) {
            Ok(s) => write!(f, "{}", s),
            Err(_) => Err(std::fmt::Error),
        }
    }
}