Skip to main content

openai_tools/audio/
response.rs

1//! OpenAI Audio API Response Types
2//!
3//! This module defines the response structures for the OpenAI Audio API.
4
5use serde::{Deserialize, Serialize};
6
7/// Response structure from transcription/translation endpoints.
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct TranscriptionResponse {
10    /// The transcribed or translated text
11    pub text: String,
12
13    /// The language of the input audio (only in verbose JSON response)
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub language: Option<String>,
16
17    /// The duration of the audio in seconds (only in verbose JSON response)
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub duration: Option<f64>,
20
21    /// Word-level timestamps (only when timestamp_granularities includes "word")
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub words: Option<Vec<Word>>,
24
25    /// Segment-level timestamps (only when timestamp_granularities includes "segment")
26    #[serde(skip_serializing_if = "Option::is_none")]
27    pub segments: Option<Vec<Segment>>,
28}
29
30/// Word-level timestamp information.
31#[derive(Debug, Clone, Serialize, Deserialize)]
32pub struct Word {
33    /// The word text
34    pub word: String,
35    /// Start time in seconds
36    pub start: f64,
37    /// End time in seconds
38    pub end: f64,
39}
40
41/// Segment-level timestamp information.
42#[derive(Debug, Clone, Serialize, Deserialize)]
43pub struct Segment {
44    /// Segment ID
45    pub id: i32,
46    /// Seek position
47    pub seek: i32,
48    /// Start time in seconds
49    pub start: f64,
50    /// End time in seconds
51    pub end: f64,
52    /// Segment text
53    pub text: String,
54    /// Token IDs
55    pub tokens: Vec<i32>,
56    /// Temperature used for generation
57    pub temperature: f64,
58    /// Average log probability
59    pub avg_logprob: f64,
60    /// Compression ratio
61    pub compression_ratio: f64,
62    /// No speech probability
63    pub no_speech_prob: f64,
64}