deepgram-rust-text-to-speech

Use ao implementar conversão de texto em fala da Deepgram no SDK Rust, incluindo seleção do modelo Aura, flags de recurso de fala, manipulação de arquivo de saída ou fluxo de bytes, e…

npx skills add https://github.com/deepgram/deepgram-rust-sdk --skill deepgram-rust-text-to-speech

Using Deepgram Text-to-Speech (Rust SDK)

Use this skill when generating audio from text with the Rust SDK's Speak surface.

When to use this product

  • Converting text into audio files with speak_to_file(...).
  • Streaming TTS bytes with speak_to_stream(...).
  • Selecting Aura voices and output encodings with speak::options::Options.

Authentication

For a TTS-only install:

[dependencies]
deepgram = { version = "0.10.0", default-features = false, features = ["speak"] }
tokio = { version = "1", features = ["full"] }
futures = "0.3"
# Only add `bytes = "1"` if you need to name `bytes::Bytes` in your own signatures.
# The code below relies on type inference and does not import bytes directly.
let dg = deepgram::Deepgram::new(std::env::var("DEEPGRAM_API_KEY")?)?;
  • API keys use Authorization: Token <api_key>.
  • The crate does not expose a TTS WebSocket client today; the supported Rust surface is REST returning a saved file or a stream of bytes.

Quick start

Quick start: save audio to a file

use std::{path::Path, time::Instant};

use deepgram::{
    speak::options::{Container, Encoding, Model, Options},
    Deepgram,
};

#[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()
        .model(Model::AuraAsteriaEn)
        .encoding(Encoding::Linear16)
        .sample_rate(16000)
        .container(Container::Wav)
        .build();

    let start = Instant::now();
    dg.text_to_speech()
        .speak_to_file("Hello from Rust.", &options, Path::new("output.wav"))
        .await?;

    println!("Time to download audio: {:.2?}", start.elapsed());
    Ok(())
}

Quick start: stream response bytes

use deepgram::{
    speak::options::{Container, Encoding, Model, Options},
    Deepgram,
};
use futures::stream::StreamExt;

#[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()
        .model(Model::AuraAsteriaEn)
        .encoding(Encoding::Linear16)
        .sample_rate(16000)
        .container(Container::Wav)
        .build();

    let mut stream = dg
        .text_to_speech()
        .speak_to_stream("Hello from Rust.", &options)
        .await?;

    while let Some(chunk) = stream.next().await {
        println!("received {} bytes", chunk.len());
    }

    Ok(())
}

Key parameters

  • Entrypoints: Deepgram::text_to_speech(), Speak::speak_to_file(...), Speak::speak_to_stream(...).
  • TTS Options builder fields: model, encoding, sample_rate, container, bit_rate.
  • Model enum lives in deepgram::speak::options::Model and includes voices such as AuraAsteriaEn, AuraLunaEn, AuraOrionEn, plus CustomId(String).
  • speak_to_stream(...) returns impl Stream<Item = bytes::Bytes>.

API reference (layered)

  1. In-repo
    • README.md
    • src/speak/rest.rs
    • src/speak/options.rs
    • examples/speak/rest/text_to_speech_to_file.rs
    • examples/speak/rest/text_to_speech_to_stream.rs
  2. OpenAPI
    • Raw spec: https://developers.deepgram.com/openapi.yaml
    • Endpoint reference: https://developers.deepgram.com/reference/text-to-speech/speak-request
  3. AsyncAPI
    • Rust SDK support: not implemented in this crate
    • Raw spec if you need unsupported WS TTS: https://developers.deepgram.com/asyncapi.yaml
  4. Context7
    • /llmstxt/developers_deepgram_llms_txt
  5. Product docs
    • https://developers.deepgram.com/docs/text-to-speech
    • https://developers.deepgram.com/docs/tts-rest

Gotchas

  1. This crate is REST-only for TTS. There is no supported Rust WebSocket TTS surface in src/speak/ today.
  2. Pick encoding/container pairs deliberately. For raw output use Container::None; for .wav output use Container::Wav.
  3. speak_to_stream(...) still uses the REST endpoint. It streams HTTP response bytes; it is not the separate TTS WebSocket API.
  4. Use API keys with Token. Do not send API keys as Bearer.

Example files in this repo

  • examples/speak/rest/text_to_speech_to_file.rs
  • examples/speak/rest/text_to_speech_to_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).

Mais skills de deepgram

deepclaw-voice
deepgram
Configure chamadas telefônicas para o OpenClaw usando a API do Deepgram Voice Agent
official
deepgram-js-audio-intelligence
deepgram
Use when writing or reviewing JavaScript/TypeScript in this repo that calls Deepgram audio analytics overlays on `/v1/listen` - summarize, topics, intents,…
official
deepgram-dotnet-audio-intelligence
deepgram
Use when writing or reviewing C# code in this repo that enables Deepgram intelligence overlays on Speech-to-Text requests. Covers `PreRecordedSchema` analytics…
official
deepgram-dotnet-management-api
deepgram
Use ao escrever ou revisar código C# neste repositório que chama as Deepgram Management APIs para projetos, modelos, chaves, membros, convites, uso, saldos e…
official
deepgram-dotnet-text-intelligence
deepgram
Use when writing or reviewing C# code in this repo that calls Deepgram Text Intelligence / Read (`/read`) for sentiment, summarization, topic detection, and…
official
deepgram-dotnet-text-to-speech
deepgram
Use when writing or reviewing C# code in this repo that calls Deepgram Text-to-Speech. Covers `ClientFactory.CreateSpeakRESTClient()` with `ToStream` /…
official
deepgram-dotnet-voice-agent
deepgram
Use when writing or reviewing C# code in this repo that builds an interactive Deepgram Voice Agent over WebSocket. Covers…
official
deepgram-go-audio-intelligence
deepgram
Use when writing or reviewing Go code in this repo that applies summaries, topics, intents, sentiment, language detection, diarization, redaction, or entity…
official