OpenAI Audio API - Text-to-speech and speech-to-text.
Values
TTS_1
TTS_1: Str "tts-1"
TTS_1_HD
TTS_1_HD: Str "tts-1-hd"
VOICE_ALLOY
VOICE_ALLOY: Str "alloy"
VOICE_ECHO
VOICE_ECHO: Str "echo"
VOICE_FABLE
VOICE_FABLE: Str "fable"
VOICE_NOVA
VOICE_NOVA: Str "nova"
VOICE_ONYX
VOICE_ONYX: Str "onyx"
VOICE_SHIMMER
VOICE_SHIMMER: Str "shimmer"
WHISPER_1
WHISPER_1: Str "whisper-1"
Functions
speak
fn (text: Str): Bytes | ::openai::api/HttpError
fn (text: Str, opts: Map): Bytes | ::openai::api/HttpError
fn (text: Str, voice: Str): Bytes | ::openai::api/HttpError
fn (text: Str, voice: Str, opts: Map): Bytes | ::openai::api/HttpError
Simple TTS - generate speech from text with default settings (tts-1 model, alloy voice).
A convenience wrapper around speech that uses sensible defaults. Pass a second argument to choose a different voice.
Example
audio-bytes ::openai::audio/speak("Hello world!")
length(audio-bytes) // => substantial byte count
::hot::file/write-file-bytes("output.mp3", audio-bytes)
Example - Custom voice
audio-bytes ::openai::audio/speak("Hello world!", "nova")
speech
fn (request: SpeechRequest): Bytes | ::openai::api/HttpError
fn (request: SpeechRequest, opts: Map): Bytes | ::openai::api/HttpError
POST /audio/speech - Generate audio from text (TTS).
Returns the raw audio bytes. Available voices: alloy, echo, fable, onyx, nova, shimmer.
Example
audio-bytes ::openai::audio/speech(::openai::audio/SpeechRequest({
model: "tts-1",
input: "Hello, this is a test.",
voice: "alloy"
}))
length(audio-bytes) // => substantial byte count
::hot::file/write-file-bytes("output.mp3", audio-bytes)
Example - Different voice
audio-bytes ::openai::audio/speech(::openai::audio/SpeechRequest({
model: "tts-1",
input: "Testing with a different voice.",
voice: "nova"
}))
Types
SpeechRequest
SpeechRequest type {
model: Str,
input: Str,
voice: Str,
response_format: Str?,
speed: Dec?
}
TranscriptionRequest
TranscriptionRequest type {
file: Str,
model: Str,
language: Str?,
prompt: Str?,
response_format: Str?,
temperature: Dec?,
timestamp_granularities: Vec<Str>?
}
TranscriptionResponse
TranscriptionResponse type {
text: Str
}
TranslationRequest
TranslationRequest type {
file: Str,
model: Str,
prompt: Str?,
response_format: Str?,
temperature: Dec?
}
TranslationResponse
TranslationResponse type {
text: Str
}