Skip to content

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

Description

@deepgram-robot

Summary

Add TTS WebSocket streaming support to the Rust SDK, enabling real-time text-to-speech audio generation. This would allow Rust developers to stream text to Deepgram and receive audio chunks in real-time, essential for voice agent and interactive applications.

Problem it solves

Rust developers building low-latency voice applications (game engines, embedded systems, real-time communication servers) need streaming TTS for interactive speech synthesis. The Rust SDK currently has an open issue (#95) for TTS WebSocket support but no implementation. TTS REST is available but doesn't support streaming, which is required for real-time voice agent use cases where audio needs to start playing before the full response is generated.

Proposed API

use deepgram::tts::{TtsWebSocket, TtsOptions, TtsEvent};

let options = TtsOptions::builder()
    .model("aura-2-en")
    .encoding(AudioEncoding::Linear16)
    .sample_rate(16000)
    .build();

let mut tts_ws = deepgram.tts().websocket(options).await?;

// Send text for synthesis
tts_ws.send_text("Hello, how can I help you today?").await?;
tts_ws.flush().await?;

// Receive audio chunks
while let Some(event) = tts_ws.next().await {
    match event? {
        TtsEvent::Audio(data) => { /* play or forward audio bytes */ },
        TtsEvent::Flushed => { /* all audio for current text received */ },
        TtsEvent::Warning(msg) => { /* handle warning */ },
    }
}

Acceptance criteria

  • TTS WebSocket client with streaming text input and audio output
  • Support for flush and close operations
  • Typed event handling (Audio, Flushed, Warning, Close)
  • Documented with usage example
  • Compatible with existing SDK async architecture (tokio)
  • Includes 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