Skip to content

[Enhancement] Add Text-to-Speech WebSocket streaming support #147

@deepgram-robot

Description

@deepgram-robot

Summary

Add WebSocket-based streaming Text-to-Speech support to the Rust SDK, enabling real-time TTS audio generation and streaming playback for voice agent and interactive applications built in Rust.

Problem it solves

The Rust SDK currently has an open issue (#95) for TTS WebSocket support. Rust developers building voice agents, game engines with voice output, or embedded voice applications need streaming TTS to achieve low-latency audio responses. The REST TTS endpoint requires waiting for the full audio to generate before playback can begin, which is unacceptable for interactive use cases. Streaming TTS via WebSocket enables sub-200ms time-to-first-audio.

Proposed API

use deepgram::{Deepgram, tts::StreamingTtsOptions};

let dg = Deepgram::new("API_KEY");

let options = StreamingTtsOptions::builder()
    .model("aura-asteria-en")
    .encoding("linear16")
    .sample_rate(24000)
    .build();

let mut tts_stream = dg.tts().stream(options).await?;

// Send text, receive audio chunks
tts_stream.send_text("Hello from Deepgram").await?;

while let Some(audio_chunk) = tts_stream.next().await {
    let chunk = audio_chunk?;
    // Play or write audio bytes
    player.write(&chunk.audio)?;
}

tts_stream.flush().await?;
tts_stream.close().await?;

Acceptance criteria

  • StreamingTtsOptions builder with model, encoding, sample_rate, and container options
  • Async WebSocket connection with Stream trait implementation for audio chunks
  • Typed audio chunk responses with metadata (word boundaries, timing)
  • Flush and close semantics matching the WebSocket TTS API
  • Documented with usage example
  • Compatible with existing API (follows established SDK patterns)
  • Includes working example in examples/ directory

Raised by the DX intelligence system.

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