Use when writing or reviewing C# code in this repo that calls Deepgram Text-to-Speech. Covers `ClientFactory.CreateSpeakRESTClient()` with `ToStream` / `ToFile`, and `ClientFactory.CreateSpeakWebSocketClient()` with `Connect`, `SpeakWithText`, `Flush`, and streaming `AudioResponse` events. Use `deepgram-dotnet-voice-agent` for full-duplex assistants instead of one-way synthesis.
86
82%
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Passed
No known issues
Convert text to audio via REST or low-latency streaming WebSocket synthesis.
Use a different skill when:
deepgram-dotnet-voice-agent.dotnet add package Deepgramusing Deepgram;
Library.Initialize();
var client = ClientFactory.CreateSpeakRESTClient();The SDK reads DEEPGRAM_API_KEY by default and also supports bearer access tokens through DeepgramHttpClientOptions / DeepgramWsClientOptions.
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.
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)
{
speakClient.SpeakWithText("Hello World!");
speakClient.Flush();
Console.ReadKey();
await speakClient.Stop();
}REST SpeakSchema: Model, BitRate, CallBack, CallBackMethod, Container, Encoding, SampleRate.
WebSocket SpeakSchema: Model, BitRate, Encoding, SampleRate.
Streaming controls: SpeakWithText, Flush, Clear, Close, SendMessageImmediately.
Deepgram/ClientFactory.csDeepgram/Clients/Speak/v1/REST/Client.csDeepgram/Clients/Speak/v2/WebSocket/Client.csDeepgram/Models/Speak/v1/REST/SpeakSchema.csDeepgram/Models/Speak/v2/WebSocket/SpeakSchema.cshttps://context7.com/deepgram/deepgram-dotnet-sdk/llmstxt/developers_deepgram_llms_txtToStream / ToFile, not GenerateAsync. Use the actual .NET names.MemoryStream. ToFile writes the file for you and then clears response.Stream.AudioResponse.Stream. You must write or play the bytes yourself.Flush(), you may wait indefinitely for the buffered text to synthesize.DeepgramWsClientOptions.AutoFlushSpeakDelta can flush automatically for token-by-token input.linear16 + 48000, your WAV header / playback path must match.StreamCallBack(...) for async REST callback processing.examples/text-to-speech/rest/file/hello-world/Program.csexamples/text-to-speech/rest/file/woodchuck/Program.csexamples/text-to-speech/websocket/simple/Program.cstests/edge_cases/tts_v1_client_example/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/skillsThis SDK ships language-idiomatic code skills; deepgram/skills ships cross-language product knowledge (see api, docs, recipes, examples, starters, setup-mcp).
d0d6fee
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.