Skip to content

[Enhancement] Add async Stream trait implementation for streaming transcription result consumption #163

Description

@deepgram-robot

Summary

Implement the futures::Stream trait for streaming transcription results, enabling Rust-idiomatic consumption of real-time transcription events using StreamExt combinators (.filter(), .map(), .take_while(), etc.) and seamless composition with the Rust async ecosystem (Tokio, async-std, tower).

Problem it solves

Rust developers expect streaming data to implement the Stream trait — it is the async equivalent of Iterator and the standard way to compose async data pipelines. Currently, consuming streaming transcription results requires callback registration, which breaks composition with Rust's rich async ecosystem. Developers cannot use StreamExt methods to filter, transform, or combine transcription streams with other async data sources. This friction makes the SDK feel non-idiomatic and increases the code required for common patterns like "take transcripts until silence" or "merge transcripts from two concurrent sessions."

Proposed API

use deepgram::stream::TranscriptionStream;
use futures::StreamExt;

let client = Deepgram::new(api_key);

// Returns a Stream<Item = TranscriptionEvent>
let mut stream: TranscriptionStream = client
    .transcription()
    .stream_audio(audio_source, options)
    .await?;

// Idiomatic Stream consumption
while let Some(event) = stream.next().await {
    match event? {
        TranscriptionEvent::Transcript(t) if t.is_final => {
            println!("{}", t.transcript);
        }
        TranscriptionEvent::UtteranceEnd(_) => break,
        _ => {}
    }
}

// Or with combinators
let final_transcripts: Vec<String> = stream
    .filter_map(|e| async move {
        match e.ok()? {
            TranscriptionEvent::Transcript(t) if t.is_final => Some(t.transcript),
            _ => None,
        }
    })
    .collect()
    .await;

Acceptance criteria

  • Implements futures::Stream<Item = Result<TranscriptionEvent, Error>>
  • Works with StreamExt combinators (filter, map, take_while, etc.)
  • Compatible with Tokio and async-std runtimes
  • Handles WebSocket lifecycle (keepalive, reconnection) internally
  • Documented with usage example
  • Compatible with existing API (additive — callback API remains available)

Raised by the DX intelligence system.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions