Deepgram bindings: pre-recorded speech-to-text (transcribe-url,
transcribe-audio), asynchronous transcription with callbacks, Aura
and Flux text-to-speech (speak, speak-flux), the public model
list, and helpers that pull transcript text, words, utterances, and
paragraphs out of a /v1/listen response. Callback verification
lives in ::deepgram::callbacks.
Live websocket streaming (wss://api.deepgram.com/v1/listen) is not
covered. For near-real-time flows, transcribe short audio chunks
with transcribe-audio.
Setup: context variable deepgram.api.key, or a per-call api-key
in the trailing opts Map of any API-calling function (see
::deepgram::api).
Quick start
out ::deepgram/transcribe-url("https://static.deepgram.com/examples/Bueller-Life-moves-pretty-fast.wav", {diarize_model: "latest", utterances: true})
::deepgram/transcript(out) // best transcript of the first channel
::deepgram/format-utterances(out) // "[Speaker 0] ..." lines
audio ::deepgram/speak("Your build is green.")
::hot::file/write-file-bytes("build.mp3", audio)
Values
BASE_URL
BASE_URL: Str "https://api.deepgram.com"
DEFAULT_LISTEN_OPTIONS
DEFAULT_LISTEN_OPTIONS: Map {
model: DEFAULT_STT_MODEL,
smart_format: true
}
DEFAULT_STT_MODEL
DEFAULT_STT_MODEL: Str "nova-3"
DEFAULT_TTS_MODEL
DEFAULT_TTS_MODEL: Str "aura-2-thalia-en"
Functions
alternative
fn (response: Map, channel: Int): Map
The best alternative of channel in a /v1/listen response, including
its transcript, confidence, and words. {} when the channel has
none. Use it for a channel other than the first, or for fields the other
helpers skip.
Example
out {results: {channels: [{alternatives: [{transcript: "Hi.", confidence: 0.98}]}]}}
::deepgram/alternative(out, 0).confidence // 0.98
::deepgram/alternative(out, 1) // {}
callback-params
fn (callback-url: Str, secret: Any): Map
Options that turn a transcription asynchronous: callback (the URL
Deepgram POSTs results to) plus, when secret is non-empty, an
extra entry callback_secret:<secret> that Deepgram echoes back in
the callback body's metadata.extra for
::deepgram::callbacks/verify-callback. Exposed for testing.
Example
::deepgram/callback-params("https://example.com/hooks/deepgram", null) // {callback: "https://example.com/hooks/deepgram"}
format-utterances
fn (response: Map): Str
Utterances as readable lines, one per turn: [Speaker 0] Hello there.
(speaker labels need diarization, e.g. diarize_model: "latest";
without them lines carry only the text). Falls back to transcript
when the response has no utterances.
Example
out {results: {utterances: [
{transcript: "Hello.", speaker: 0},
{transcript: "Hi.", speaker: 1}
]}}
::deepgram/format-utterances(out) // "[Speaker 0] Hello.\n[Speaker 1] Hi."
is-accepted
fn (response: Map): Bool
True for the acknowledgement of an async (callback) request: a
request_id with no results yet.
Example
::deepgram/is-accepted({request_id: "req-2"}) // true
::deepgram/is-accepted({request_id: "req-2", results: {}}) // false
list-models
fn (): Map
fn (include-outdated: Bool): Map
fn (opts: Map): Map
fn (include-outdated: Bool, opts: Map): Map
GET /v1/models: the latest public models as {stt: [...], tts: [...]}
(each with name, canonical_name, languages, ...; TTS entries
carry voice metadata). Pass true to include outdated versions.
Example
voices map(::deepgram/list-models().tts, (m) { m.canonical_name })
deepgram.api.key
listen-params
fn (options: Map): Map
Merge options over the transcription defaults (model: "nova-3",
smart_format: true). A Map extra becomes Deepgram's repeated
extra=key:value form. Exposed for testing.
Example
::deepgram/listen-params({language: "es"}).language // "es"
::deepgram/listen-params({}).model // "nova-3"
::deepgram/listen-params({extra: {job: "42"}}).extra // ["job:42"]
listen-path
fn (options: Map): Str
The /v1/listen path with query string for options (defaults
applied). Exposed for testing.
Example
::deepgram/listen-path({model: "nova-2", smart_format: null}) // "/v1/listen?model=nova-2"
paragraph-transcript
fn (response: Map): Str
The paragraph-formatted transcript (blank lines between paragraphs) when
the request set paragraphs: true, otherwise the plain transcript.
Example
out {results: {channels: [{alternatives: [{
transcript: "One. Two.",
paragraphs: {transcript: "One.\n\nTwo."}
}]}]}}
::deepgram/paragraph-transcript(out) // "One.\n\nTwo."
paragraphs
fn (response: Map): Vec
Paragraph objects ({sentences: [{text, start, end}], speaker?, num_words, start, end}) of the first channel, present when the request
set paragraphs: true; [] otherwise.
Example
out {results: {channels: [{alternatives: [{paragraphs: {paragraphs: [{num_words: 4, speaker: 0}]}}]}]}}
map(::deepgram/paragraphs(out), %.num_words) // [4]
::deepgram/paragraphs({}) // []
request-id
fn (response: Map): Str?
The request id of a /v1/listen response: metadata.request_id for a
finished transcription, or the top-level request_id of an async
acknowledgement.
Example
::deepgram/request-id({metadata: {request_id: "req-1"}}) // "req-1"
::deepgram/request-id({request_id: "req-2"}) // "req-2"
speak
fn (text: Str): Bytes
fn (text: Str, options: Map): Bytes
fn (text: Str, options: Map, opts: Map): Bytes
POST /v1/speak: Aura text-to-speech. Returns the audio as Bytes
(mp3 by default). options: model (default "aura-2-thalia-en";
Aura-2 voices are named aura-2-<voice>-<lang>, e.g.
"aura-2-orion-en", "aura-2-celeste-es"), encoding (linear16,
mulaw, alaw, mp3, opus, flac, aac), container,
sample_rate, bit_rate, speed (0.7-1.5), tag.
Example
audio ::deepgram/speak("Your build is green.", {model: "aura-2-orion-en"})
phone ::deepgram/speak("Press one to continue.", {encoding: "mulaw", sample_rate: 8000, container: "none"})
deepgram.api.key
speak-flux
fn (text: Str, model: Str): Bytes
fn (text: Str, model: Str, options: Map): Bytes
fn (text: Str, model: Str, options: Map, opts: Map): Bytes
POST /v2/speak: Flux text-to-speech (batch). model is required and
must be a Flux voice (e.g. "flux-alexis-en"). Takes the same audio
options as speak plus expressivity (-2 to 2). Returns Bytes.
Example
audio ::deepgram/speak-flux("Welcome back.", "flux-alexis-en", {expressivity: 1})
deepgram.api.key
speak-path
fn (options: Map): Str
The /v1/speak path with query string for options (default model
applied). Exposed for testing.
Example
::deepgram/speak-path({}) // "/v1/speak?model=aura-2-thalia-en"
::deepgram/speak-path({model: "aura-2-orion-en"}) // "/v1/speak?model=aura-2-orion-en"
transcribe-audio
fn (audio: Bytes): Map
fn (audio: Bytes, options: Map): Map
fn (audio: Bytes, options: Map, mime-type: Str): Map
fn (audio: Bytes, options: Map, opts: Map): Map
fn (audio: Bytes, options: Map, mime-type: Str, opts: Map): Map
POST /v1/listen with raw audio Bytes (wav, mp3, ogg, flac, webm,
m4a, ...). Same options as transcribe-url. Deepgram detects
containerized formats itself, so the body goes up as
application/octet-stream unless you pass a MIME type (3-arity).
Headerless audio needs encoding and sample_rate options
(e.g. {encoding: "linear16", sample_rate: 16000}).
Example
audio ::hot::file/read-file-bytes("call.mp3")
::deepgram/transcript(::deepgram/transcribe-audio(audio))
deepgram.api.key
transcribe-audio-async
fn (audio: Bytes, callback-url: Str): Str
fn (audio: Bytes, callback-url: Str, options: Map): Str
fn (audio: Bytes, callback-url: Str, options: Map, opts: Map): Str
Asynchronous transcribe-audio: uploads the Bytes, returns Deepgram's
request_id, and delivers the result to callback-url. See
transcribe-url-async.
Example
audio ::hot::file/read-file-bytes("call.mp3")
request-id ::deepgram/transcribe-audio-async(audio, "https://example.com/hooks/deepgram", {diarize_model: "latest"})
deepgram.api.key, deepgram.callback.secret
transcribe-url
fn (audio-url: Str): Map
fn (audio-url: Str, options: Map): Map
fn (audio-url: Str, options: Map, opts: Map): Map
POST /v1/listen with a hosted audio URL. options map to Deepgram
query params and are merged over model: "nova-3" and
smart_format: true. Common ones: language (or "multi"),
detect_language, diarize_model ("latest"; replaces the
deprecated diarize), utterances, paragraphs, punctuate,
keyterm (Vec, Nova-3), keywords (Vec, older models), search,
replace, redact, summarize, topics, intents, sentiment,
multichannel, tag, extra. Vec values repeat the key.
Returns the full response Map; use transcript, words,
utterances, or paragraphs to read it.
Example
out ::deepgram/transcribe-url("https://static.deepgram.com/examples/Bueller-Life-moves-pretty-fast.wav", {
keyterm: ["Bueller", "Ferris"],
paragraphs: true
})
::deepgram/paragraph-transcript(out)
deepgram.api.key
transcribe-url-async
fn (audio-url: Str, callback-url: Str): Str
fn (audio-url: Str, callback-url: Str, options: Map): Str
fn (audio-url: Str, callback-url: Str, options: Map, opts: Map): Str
Asynchronous transcribe-url: Deepgram answers at once with a
request_id (returned here) and later POSTs the full transcription
response to callback-url. When deepgram.callback.secret is set it
is sent as extra=callback_secret:<secret> so your handler can check
it with ::deepgram::callbacks/verify-callback. Use
{callback_method: "PUT"} to receive a PUT instead.
Deepgram only calls back on ports 80, 443, 8080, and 8443, and retries a non-2xx answer up to 10 times, 30 seconds apart.
Example
request-id ::deepgram/transcribe-url-async("https://static.deepgram.com/examples/Bueller-Life-moves-pretty-fast.wav", "https://example.com/hooks/deepgram", {utterances: true})
deepgram.api.key, deepgram.callback.secret
transcript
fn (response: Map): Str
The best transcript text of the first channel ("" when the response
has none).
Example
out {results: {channels: [{alternatives: [{transcript: "Hello there."}]}]}}
::deepgram/transcript(out) // "Hello there."
::deepgram/transcript({}) // ""
transcripts
fn (response: Map): Vec
The best transcript of every channel, in channel order (for
multichannel: true).
Example
out {results: {channels: [
{alternatives: [{transcript: "Left."}]},
{alternatives: [{transcript: "Right."}]}
]}}
::deepgram/transcripts(out) // ["Left.", "Right."]
utterances
fn (response: Map): Vec
Utterances ({start, end, confidence, channel, transcript, speaker?, words, id}), present when the request set utterances: true; []
otherwise.
Example
out {results: {utterances: [{transcript: "Hello.", speaker: 0}]}}
map(::deepgram/utterances(out), %.transcript) // ["Hello."]
::deepgram/utterances({}) // []
words
fn (response: Map): Vec
Word objects of the first channel's best alternative: {word, start, end, confidence, punctuated_word?, speaker?}.
Example
out {results: {channels: [{alternatives: [{words: [{word: "hello"}, {word: "there"}]}]}]}}
map(::deepgram/words(out), %.word) // ["hello", "there"]