A robust OpenAI Text-to-Speech provider implementation that integrates with a generic TTS trait for seamless audio synthesis in Rust applications.
// Source: https://github.com/moltis-org/moltis | License: MIT | Copyright 2025 Fabien Penso
// Provided via justclaw.it.com; keep this notice with the code.
//! OpenAI TTS provider implementation.
//!
//! OpenAI offers text-to-speech with multiple voices and two quality tiers:
//! - tts-1: Optimized for real-time, lower latency
//! - tts-1-hd: Higher quality, slightly higher latency
use {
anyhow::{Context, Result, anyhow},
async_trait::async_trait,
reqwest::Client,
secrecy::{ExposeSecret, Secret},
serde::Serialize,
};
use super::{AudioFormat, AudioOutput, SynthesizeRequest, TtsProvider, Voice};
/// OpenAI API base URL.
const API_BASE: &str = "https://api.openai.com/v1";
/// Default voice.
const DEFAULT_VOICE: &str = "alloy";
/// Default model (real-time optimized)
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key