Using Deepgram Speech-to-Text (Rust SDK)
Use this skill for prerecorded transcription, live streaming transcription, or when mapping Deepgram docs to the Rust crate's real listen surface.
When to use this product
- Transcribing local files, URLs, or in-memory audio with
Deepgram::transcription().
- Streaming audio over WebSocket with
stream_request() / stream_request_with_options(...).
- Using
common::options::Options for STT features such as model, language, punctuate, diarize, smart_format, utterances, and streaming knobs like endpointing.
This skill covers Nova models on /v1/listen — Deepgram's general-purpose STT family (nova-3, nova-2, nova, enhanced, base). Both Nova and Flux are actively maintained, industry-leading STT model families.
Use a different skill when:
- You need conversational-audio transcription with built-in turn detection (voice agents, interactive assistants) →
deepgram-rust-conversational-stt (Flux on /v2/listen).
- You want analytics overlays on the transcript (summarize, sentiment, topics, intents) →
deepgram-rust-audio-intelligence (same /v1/listen endpoint, different params).
- You need a full-duplex voice agent (STT + LLM + TTS in one WSS) →
deepgram-rust-voice-agent.
Authentication
deepgram defaults to manage + listen + speak. For STT-only installs, trim features explicitly:
[dependencies]
deepgram = { version = "0.10.0", default-features = false, features = ["listen"] }
tokio = { version = "1", features = ["full"] }
futures = "0.3"
use deepgram::Deepgram;
let dg = Deepgram::new(std::env::var("DEEPGRAM_API_KEY")?)?;
- API keys use
Authorization: Token <api_key>.
- Temporary tokens use
Deepgram::with_temp_token(...) and send Bearer, but are mainly useful for voice APIs rather than Manage APIs.
- Self-hosted installs can use
Deepgram::with_base_url(...) or Deepgram::with_base_url_and_api_key(...).
Quick start
Quick start: prerecorded file transcription
use deepgram::{
common::{
audio_source::AudioSource,
options::{Language, Options},
},
Deepgram,
};
use tokio::fs::File;
static PATH_TO_FILE: &str = "examples/audio/bueller.wav";
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = std::env::var("DEEPGRAM_API_KEY")?;
let dg = Deepgram::new(&api_key)?;
let file = File::open(PATH_TO_FILE).await?;
let source = AudioSource::from_buffer_with_mime_type(file, "audio/wav");
let options = Options::builder()
.punctuate(true)
.language(Language::en_US)
.build();
let response = dg.transcription().prerecorded(source, &options).await?;
println!("{}", response.results.channels[0].alternatives[0].transcript);
Ok(())
}
Quick start: live WebSocket transcription
use std::time::Duration;
use deepgram::{
common::options::{Encoding, Endpointing, Language, Options},
Deepgram,
};
use futures::stream::StreamExt;
static PATH_TO_FILE: &str = "examples/audio/bueller.wav";
static AUDIO_CHUNK_SIZE: usize = 3174;
static FRAME_DELAY: Duration = Duration::from_millis(16);
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = std::env::var("DEEPGRAM_API_KEY")?;
let dg = Deepgram::new(&api_key)?;
let options = Options::builder()
.smart_format(true)
.language(Language::en_US)
.build();
let mut results = dg
.transcription()
.stream_request_with_options(options)
.keep_alive()
.encoding(Encoding::Linear16)
.sample_rate(44100)
.channels(2)
.endpointing(Endpointing::CustomDurationMs(300))
.interim_results(true)
.utterance_end_ms(1000)
.vad_events(true)
.no_delay(true)
.file(PATH_TO_FILE, AUDIO_CHUNK_SIZE, FRAME_DELAY)
.await?;
println!("Deepgram Request ID: {}", results.request_id());
while let Some(result) = results.next().await {
println!("{result:?}");
}
Ok(())
}
Key parameters
- Prerecorded entrypoints:
prerecorded(...), prerecorded_callback(...), make_prerecorded_request_builder(...).
- Streaming entrypoints:
stream_request(), stream_request_with_options(options), then .file(...), .stream(...), or .handle().await?.
- Core
Options builder fields: model, language, punctuate, smart_format, diarize, multichannel, utterances, detect_language, keywords, search, replace, paragraphs.
- Streaming-only builder fields:
encoding, sample_rate, channels, endpointing, utterance_end_ms, interim_results, no_delay, vad_events, keep_alive, callback.
- Main response types: prerecorded
common::batch_response::Response; live common::stream_response::StreamResponse.
API reference (layered)
- In-repo
README.md
src/listen/rest.rs
src/listen/websocket.rs
src/common/options.rs
examples/transcription/rest/prerecorded_from_file.rs
examples/transcription/websocket/simple_stream.rs
- OpenAPI
- Raw spec:
https://developers.deepgram.com/openapi.yaml
- Pre-recorded reference:
https://developers.deepgram.com/reference/speech-to-text/listen-pre-recorded
- AsyncAPI
- Raw spec:
https://developers.deepgram.com/asyncapi.yaml
- Streaming reference:
https://developers.deepgram.com/reference/speech-to-text/listen-streaming
- Context7
/llmstxt/developers_deepgram_llms_txt
- Product docs
https://developers.deepgram.com/docs/stt/getting-started
Gotchas
- Use
listen feature gates correctly. STT modules are behind the listen Cargo feature.
Options is by value for WebSocket builders. stream_request_with_options(options) takes ownership, unlike prerecorded APIs that take &Options.
- Live and prerecorded responses differ. Intelligence-heavy fields such as
summary, topics, and sentiments live on prerecorded response types, not StreamResponse.
- Audio pacing matters. The example
.file(...) helpers assume realistic chunk sizes and delays; sending audio too fast can produce bad streaming behavior.
- Use
Token, not Bearer, for API keys. Bearer is only for temporary tokens.
Example files in this repo
examples/transcription/rest/prerecorded_from_file.rs
examples/transcription/rest/prerecorded_from_url.rs
examples/transcription/rest/callback.rs
examples/transcription/rest/make_prerecorded_request_builder.rs
examples/transcription/websocket/simple_stream.rs
examples/transcription/websocket/callback_stream.rs
examples/transcription/websocket/microphone_stream.rs
examples/transcription/websocket/16_keepalive_close_stream.rs
Central product skills
For cross-language Deepgram product knowledge — the consolidated API reference, documentation finder, focused runnable recipes, third-party integration examples, and MCP setup — install the central skills:
npx skills add deepgram/skills
This SDK ships language-idiomatic code skills; deepgram/skills ships cross-language product knowledge (see api, docs, recipes, examples, starters, setup-mcp).
1---2name: deepgram-rust-speech-to-text3description: Use when implementing Deepgram speech-to-text in the Rust SDK, including prerecorded REST transcription, live WebSocket streaming, listen feature flags, Options builder usage, and response handling.4---56# Using Deepgram Speech-to-Text (Rust SDK)78Use this skill for prerecorded transcription, live streaming transcription, or when mapping Deepgram docs to the Rust crate's real `listen` surface.910## When to use this product1112- Transcribing local files, URLs, or in-memory audio with `Deepgram::transcription()`.13- Streaming audio over WebSocket with `stream_request()` / `stream_request_with_options(...)`.14- Using `common::options::Options` for STT features such as `model`, `language`, `punctuate`, `diarize`, `smart_format`, `utterances`, and streaming knobs like `endpointing`.1516This skill covers **Nova models on `/v1/listen`** — Deepgram's general-purpose STT family (nova-3, nova-2, nova, enhanced, base). Both Nova and Flux are actively maintained, industry-leading STT model families.1718**Use a different skill when:**19- You need conversational-audio transcription with built-in turn detection (voice agents, interactive assistants) → `deepgram-rust-conversational-stt` (Flux on `/v2/listen`).20- You want analytics overlays on the transcript (summarize, sentiment, topics, intents) → `deepgram-rust-audio-intelligence` (same `/v1/listen` endpoint, different params).21- You need a full-duplex voice agent (STT + LLM + TTS in one WSS) → `deepgram-rust-voice-agent`.2223## Authentication2425`deepgram` defaults to `manage + listen + speak`. For STT-only installs, trim features explicitly:2627```toml28[dependencies]29deepgram = { version = "0.10.0", default-features = false, features = ["listen"] }30tokio = { version = "1", features = ["full"] }31futures = "0.3"32```3334```rust35use deepgram::Deepgram;3637let dg = Deepgram::new(std::env::var("DEEPGRAM_API_KEY")?)?;38```3940- API keys use `Authorization: Token <api_key>`.41- Temporary tokens use `Deepgram::with_temp_token(...)` and send `Bearer`, but are mainly useful for voice APIs rather than Manage APIs.42- Self-hosted installs can use `Deepgram::with_base_url(...)` or `Deepgram::with_base_url_and_api_key(...)`.4344## Quick start4546## Quick start: prerecorded file transcription4748```rust49use deepgram::{50 common::{51 audio_source::AudioSource,52 options::{Language, Options},53 },54 Deepgram,55};56use tokio::fs::File;5758static PATH_TO_FILE: &str = "examples/audio/bueller.wav";5960#[tokio::main]61async fn main() -> Result<(), Box<dyn std::error::Error>> {62 let api_key = std::env::var("DEEPGRAM_API_KEY")?;63 let dg = Deepgram::new(&api_key)?;6465 let file = File::open(PATH_TO_FILE).await?;66 let source = AudioSource::from_buffer_with_mime_type(file, "audio/wav");6768 let options = Options::builder()69 .punctuate(true)70 .language(Language::en_US)71 .build();7273 let response = dg.transcription().prerecorded(source, &options).await?;74 println!("{}", response.results.channels[0].alternatives[0].transcript);75 Ok(())76}77```7879## Quick start: live WebSocket transcription8081```rust82use std::time::Duration;8384use deepgram::{85 common::options::{Encoding, Endpointing, Language, Options},86 Deepgram,87};88use futures::stream::StreamExt;8990static PATH_TO_FILE: &str = "examples/audio/bueller.wav";91static AUDIO_CHUNK_SIZE: usize = 3174;92static FRAME_DELAY: Duration = Duration::from_millis(16);9394#[tokio::main]95async fn main() -> Result<(), Box<dyn std::error::Error>> {96 let api_key = std::env::var("DEEPGRAM_API_KEY")?;97 let dg = Deepgram::new(&api_key)?;9899 let options = Options::builder()100 .smart_format(true)101 .language(Language::en_US)102 .build();103104 let mut results = dg105 .transcription()106 .stream_request_with_options(options)107 .keep_alive()108 .encoding(Encoding::Linear16)109 .sample_rate(44100)110 .channels(2)111 .endpointing(Endpointing::CustomDurationMs(300))112 .interim_results(true)113 .utterance_end_ms(1000)114 .vad_events(true)115 .no_delay(true)116 .file(PATH_TO_FILE, AUDIO_CHUNK_SIZE, FRAME_DELAY)117 .await?;118119 println!("Deepgram Request ID: {}", results.request_id());120 while let Some(result) = results.next().await {121 println!("{result:?}");122 }123124 Ok(())125}126```127128## Key parameters129130- Prerecorded entrypoints: `prerecorded(...)`, `prerecorded_callback(...)`, `make_prerecorded_request_builder(...)`.131- Streaming entrypoints: `stream_request()`, `stream_request_with_options(options)`, then `.file(...)`, `.stream(...)`, or `.handle().await?`.132- Core `Options` builder fields: `model`, `language`, `punctuate`, `smart_format`, `diarize`, `multichannel`, `utterances`, `detect_language`, `keywords`, `search`, `replace`, `paragraphs`.133- Streaming-only builder fields: `encoding`, `sample_rate`, `channels`, `endpointing`, `utterance_end_ms`, `interim_results`, `no_delay`, `vad_events`, `keep_alive`, `callback`.134- Main response types: prerecorded `common::batch_response::Response`; live `common::stream_response::StreamResponse`.135136## API reference (layered)1371381. **In-repo**139 - `README.md`140 - `src/listen/rest.rs`141 - `src/listen/websocket.rs`142 - `src/common/options.rs`143 - `examples/transcription/rest/prerecorded_from_file.rs`144 - `examples/transcription/websocket/simple_stream.rs`1452. **OpenAPI**146 - Raw spec: `https://developers.deepgram.com/openapi.yaml`147 - Pre-recorded reference: `https://developers.deepgram.com/reference/speech-to-text/listen-pre-recorded`1483. **AsyncAPI**149 - Raw spec: `https://developers.deepgram.com/asyncapi.yaml`150 - Streaming reference: `https://developers.deepgram.com/reference/speech-to-text/listen-streaming`1514. **Context7**152 - `/llmstxt/developers_deepgram_llms_txt`1535. **Product docs**154 - `https://developers.deepgram.com/docs/stt/getting-started`155156## Gotchas1571581. **Use `listen` feature gates correctly.** STT modules are behind the `listen` Cargo feature.1592. **`Options` is by value for WebSocket builders.** `stream_request_with_options(options)` takes ownership, unlike prerecorded APIs that take `&Options`.1603. **Live and prerecorded responses differ.** Intelligence-heavy fields such as `summary`, `topics`, and `sentiments` live on prerecorded response types, not `StreamResponse`.1614. **Audio pacing matters.** The example `.file(...)` helpers assume realistic chunk sizes and delays; sending audio too fast can produce bad streaming behavior.1625. **Use `Token`, not `Bearer`, for API keys.** `Bearer` is only for temporary tokens.163164## Example files in this repo165166- `examples/transcription/rest/prerecorded_from_file.rs`167- `examples/transcription/rest/prerecorded_from_url.rs`168- `examples/transcription/rest/callback.rs`169- `examples/transcription/rest/make_prerecorded_request_builder.rs`170- `examples/transcription/websocket/simple_stream.rs`171- `examples/transcription/websocket/callback_stream.rs`172- `examples/transcription/websocket/microphone_stream.rs`173- `examples/transcription/websocket/16_keepalive_close_stream.rs`174175## Central product skills176177For cross-language Deepgram product knowledge — the consolidated API reference, documentation finder, focused runnable recipes, third-party integration examples, and MCP setup — install the central skills:178179```bash180npx skills add deepgram/skills181```182183This SDK ships language-idiomatic code skills; `deepgram/skills` ships cross-language product knowledge (see `api`, `docs`, `recipes`, `examples`, `starters`, `setup-mcp`).