Skip to main content

openai_interface/audio/
mod.rs

1//! Turn audio into text or text into audio.
2//!
3//! Submodules: `speech` (text-to-speech, binary response),
4//! `transcriptions` (speech-to-text in the input language), and
5//! `translations` (speech-to-English). Streaming transcriptions (`stream`)
6//! and `stream_format` audio streaming are not supported yet.
7//!
8//! > ![warn] The endpoints in this module are untested!
9//! > No OpenAI-compatible provider accessible to this project (DeepSeek,
10//! > Alibaba Cloud Model Studio) implements the `/audio/*` endpoints, and
11//! > no OpenAI API key was available for testing. If you encounter any
12//! > issues, please report them on the repository.
13
14pub mod speech;
15pub mod transcriptions;
16pub mod translations;
17
18use serde::Serialize;
19
20/// The format of the transcription/translation output, in one of these
21/// options: `json`, `text`, `srt`, `verbose_json`, or `vtt`.
22///
23/// `diarized_json` (for `gpt-4o-transcribe-diarize`) is not covered by this
24/// type yet; pass it through the request's `extra_body`-style escape hatch
25/// if needed.
26#[derive(Debug, Serialize, Clone, Copy, PartialEq, Eq)]
27#[serde(rename_all = "snake_case")]
28pub enum AudioResponseFormat {
29    Json,
30    Text,
31    Srt,
32    VerboseJson,
33    Vtt,
34}
35
36/// Serializes a unit-variant enum value to its bare string literal, e.g.
37/// `Json` -> `"json"`. Used for multipart text fields.
38pub(super) fn enum_to_literal<T: Serialize>(value: &T) -> Result<String, crate::errors::OapiError> {
39    serde_json::to_string(value)
40        .map(|json| json.trim_matches('"').to_string())
41        .map_err(|e| {
42            crate::errors::OapiError::ResponseError(format!("Failed to serialize field: {e}"))
43        })
44}