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` /…

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

Using Deepgram Text-to-Speech (.NET SDK)

Convert text to audio via REST or low-latency streaming WebSocket synthesis.

When to use this product

  • REST — synthesize complete text and save or process the returned audio.
  • WebSocket — stream text into Deepgram and receive audio chunks back incrementally.

Use a different skill when:

  • You need an agent that listens, thinks, and speaks in one session → deepgram-dotnet-voice-agent.

Authentication

dotnet add package Deepgram
using Deepgram;

Library.Initialize();
var client = ClientFactory.CreateSpeakRESTClient();

The SDK reads DEEPGRAM_API_KEY by default and also supports bearer access tokens through DeepgramHttpClientOptions / DeepgramWsClientOptions.

Quick start — REST

using Deepgram;
using Deepgram.Models.Speak.v1.REST;

Library.Initialize();

var client = ClientFactory.CreateSpeakRESTClient();
var response = await client.ToFile(
    new TextSource("Hello World!"),
    "output.mp3",
    new SpeakSchema()
    {
        Model = "aura-2-thalia-en",
    });

Console.WriteLine(response);

If you want the bytes in memory, call ToStream(...) and read response.Stream.

Quick start — WebSocket

using Deepgram;
using Deepgram.Models.Speak.v2.WebSocket;

Library.Initialize();

var speakClient = ClientFactory.CreateSpeakWebSocketClient();

await speakClient.Subscribe(new EventHandler<AudioResponse>((sender, e) =>
{
    if (e.Stream != null)
    {
        // Streaming Speak (Encoding = "linear16") delivers raw PCM — no WAV header.
        // Save as .raw, or prepend a valid WAV header (see examples/text-to-speech/websocket/simple/Program.cs).
        using (var writer = new BinaryWriter(File.Open("output.raw", FileMode.Append)))
        {
            writer.Write(e.Stream.ToArray());
        }
    }
}));

bool connected = await speakClient.Connect(new SpeakSchema()
{
    Encoding = "linear16",
    SampleRate = 48000,
});

if (!connected)
{
    Console.Error.WriteLine("WebSocket connection failed — check API key and network.");
    return;
}

speakClient.SpeakWithText("Hello World!");
speakClient.Flush();
Console.ReadKey();
await speakClient.Stop();

Key params

REST SpeakSchema: Model, BitRate, CallBack, CallBackMethod, Container, Encoding, SampleRate.

WebSocket SpeakSchema: Model, BitRate, Encoding, SampleRate.

Streaming controls: SpeakWithText, Flush, Clear, Close, SendMessageImmediately.

References

Gotchas

  1. Methods are ToStream / ToFile, not GenerateAsync. Use the actual .NET names.
  2. REST returns audio metadata plus a MemoryStream. ToFile writes the file for you and then clears response.Stream.
  3. WebSocket output arrives as AudioResponse.Stream. You must write or play the bytes yourself.
  4. Flush matters. If you never call Flush(), you may wait indefinitely for the buffered text to synthesize.
  5. Autoflush is configurable. DeepgramWsClientOptions.AutoFlushSpeakDelta can flush automatically for token-by-token input.
  6. Match output format to your sink. If you request linear16 + 48000, your WAV header / playback path must match.
  7. Callback flows are separate. Use StreamCallBack(...) for async REST callback processing.

Example files in this repo

  • examples/text-to-speech/rest/file/hello-world/Program.cs
  • examples/text-to-speech/rest/file/woodchuck/Program.cs
  • examples/text-to-speech/websocket/simple/Program.cs
  • tests/edge_cases/tts_v1_client_example/

Cross-language product knowledge (API reference, recipes, MCP setup): npx skills add deepgram/skills.

deepgramのその他のスキル

deepclaw-voice
deepgram
Deepgram Voice Agent APIを使用してOpenClawへの電話発信を設定する
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-js-conversational-stt
deepgram
Use when writing or reviewing JavaScript/TypeScript in this repo that calls Deepgram Conversational STT v2 / Flux (`/v2/listen`) for turn-aware streaming…
official
deepgram-dotnet-conversational-stt
deepgram
会話型音声認識、Fluxスタイルのリアルタイム文字起こし、またはターンテイキングストリーミングのためのC#コードを評価、拡張、または作成する際に使用します。
official
deepgram-dotnet-management-api
deepgram
このリポジトリ内で、Deepgram Management APIを呼び出してプロジェクト、モデル、キー、メンバー、招待、使用量、残高などを扱うC#コードを記述またはレビューする際に使用します。
official
deepgram-dotnet-speech-to-text
deepgram
このリポジトリ内で、録音済みまたはライブの文字起こしのためにDeepgram Speech-to-Textを呼び出すC#コードを記述またはレビューする際に使用します。対象範囲は…
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-voice-agent
deepgram
このリポジトリ内で、WebSocketを介したインタラクティブなDeepgram Voice Agentを構築するC#コードを作成またはレビューする際に使用します。対象範囲は…
official