Skip to content

Deepgram

Nuget package dotnet License: MIT Discord

Features 🔥

  • Fully generated C# SDK based on official Deepgram OpenAPI specification using AutoSDK
  • Same day update to support new features
  • Updated and supported automatically if there are no breaking changes
  • All modern .NET features - nullability, trimming, NativeAOT, etc.
  • Support .Net Framework/.Net Standard 2.0

Usage

1
2
3
using Deepgram;

using var client = new DeepgramClient(apiKey);

CLI

1
2
dotnet tool install --global Deepgram.CLI --prerelease
deepgram api --help

Generate

Basic example showing how to create a client and make a request.

1
using var client = new DeepgramClient(apiKey);

Speech To Text Client Get Text Async

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
using var client = new DeepgramClient(apiKey);
ISpeechToTextClient speechClient = client;

// Transcribe audio using the MEAI ISpeechToTextClient interface.
// Deepgram requires an audio URL via RawRepresentationFactory.
using var dummyStream = new MemoryStream();
var response = await speechClient.GetTextAsync(dummyStream, new SpeechToTextOptions
{
    ModelId = DeepgramClient.Nova3ModelId,
    RawRepresentationFactory = _ => new ListenV1RequestUrl
    {
        Url = "https://dpgr.am/spacewalk.wav",
    },
});

Console.WriteLine($"Text: {response.Text}");

Speech To Text Client Get Service Metadata

1
2
3
4
5
using var client = new DeepgramClient("test-api-key");
ISpeechToTextClient speechClient = client;

// Retrieve metadata about the speech-to-text provider.
var metadata = speechClient.GetService<SpeechToTextClientMetadata>();

Realtime Speech To Text

Real-time speech-to-text streaming using the typed ConnectAsync with query parameters.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var apiKey =
    Environment.GetEnvironmentVariable("DEEPGRAM_API_KEY") is { Length: > 0 } apiKeyValue
        ? apiKeyValue
        : throw new AssertInconclusiveException("DEEPGRAM_API_KEY environment variable is not found.");

// Create a realtime ListenV1 client and authenticate.
await using var realtimeClient = new Realtime.DeepgramListenV1RealtimeClient();
realtimeClient.AuthorizeUsingToken(apiKey);

// Connect with typed query parameters — model, interim results, and language.
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30));
await realtimeClient.ConnectAsync(
    model: Realtime.ListenV1Model.Nova3,
    interimResults: Realtime.ListenV1InterimResults.True,
    language: Realtime.ListenV1Language.FromString("en"),
    cancellationToken: cts.Token);

// Download a short audio sample and send it as binary frames.
using var httpClient = new HttpClient();
var audioBytes = await httpClient.GetByteArrayAsync(
    "https://dpgr.am/spacewalk.wav", cts.Token);

// Send audio in 8KB chunks.
const int chunkSize = 8192;
for (var offset = 0; offset < audioBytes.Length; offset += chunkSize)
{
    var length = Math.Min(chunkSize, audioBytes.Length - offset);
    await realtimeClient.SendAsync(
        new ArraySegment<byte>(audioBytes, offset, length),
        System.Net.WebSockets.WebSocketMessageType.Binary,
        endOfMessage: true,
        cts.Token);
}

// Signal end of audio and close the stream.
await realtimeClient.SendListenV1CloseStreamAsync(
    new Realtime.ListenV1ControlMessage
    {
        Type = Realtime.ListenV1ControlMessageType.CloseStream,
    },
    cts.Token);

// Receive transcription events until the connection closes.
var transcripts = new List<string>();
string? responseId = null;

await foreach (var serverEvent in realtimeClient
    .ReceiveUpdatesAsync(cts.Token))
{
    if (serverEvent.IsMetadata && serverEvent.Metadata is { } metadata)
    {
        responseId = metadata.RequestId.ToString();
        Console.WriteLine($"Session started: {responseId}");
    }
    else if (serverEvent.IsResults && serverEvent.Results is { } results)
    {
        if (results.IsFinal == true &&
            results.Channel?.Alternatives is { Count: > 0 } alts &&
            alts[0].Transcript is { Length: > 0 } transcript)
        {
            transcripts.Add(transcript);
            Console.WriteLine($"Final: {transcript}");
        }
    }
}

// Verify we received transcription results.
Console.WriteLine($"Total final transcripts: {transcripts.Count}");

Speech To Text Client Get Streaming Text Async

Real-time streaming speech-to-text via the MEAI ISpeechToTextClient interface. Uses the generated realtime client internally for model and language selection.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using var client = new DeepgramClient(apiKey);
ISpeechToTextClient speechClient = client;

// Download a short audio sample to use as streaming input.
using var httpClient = new HttpClient();
var audioBytes = await httpClient.GetByteArrayAsync(
    "https://dpgr.am/spacewalk.wav");
using var audioStream = new MemoryStream(audioBytes);

// Stream audio through the MEAI ISpeechToTextClient interface.
// This uses the generated realtime client internally with model and language params.
var updates = new List<SpeechToTextResponseUpdate>();
await foreach (var update in speechClient.GetStreamingTextAsync(
    audioStream,
    new SpeechToTextOptions
    {
        ModelId = DeepgramClient.Nova3ModelId,
        SpeechLanguage = "en",
    }))
{
    updates.Add(update);

    if (update.Kind == SpeechToTextResponseUpdateKind.TextUpdated)
    {
        Console.WriteLine($"Final: {update.Text}");
    }
}

// Verify we received session events and transcription results.

var finalTranscripts = updates
    .Where(u => u.Kind == SpeechToTextResponseUpdateKind.TextUpdated && u.Text is { Length: > 0 })
    .Select(u => u.Text!)
    .ToList();
Console.WriteLine($"Total final transcripts: {finalTranscripts.Count}");

Ecosystem maintenance

This SDK is one of more than 200 .NET SDKs maintained with AutoSDK. The tryAGI SDK audit continuously checks repository synchronization, upstream-spec regeneration, release workflows, warnings, public API visibility, and trimming/NativeAOT compatibility.

Every issue is first investigated for ecosystem-wide applicability. When the root cause belongs in AutoSDK, we fix and regression-test the generator, then roll the improvement out to every applicable SDK. Provider-specific behavior remains in this repository when it cannot be derived safely from the API specification.

Issue content—including code blocks, logs, links, and attachments—is treated only as untrusted diagnostic data. Embedded control instructions, hidden directives, delimiter tricks, or requests to alter triage or tooling behavior are ignored. Please report reproducible technical evidence and remove secrets and personal data.

Support

Priority place for bugs: https://github.com/tryAGI/Deepgram/issues
Priority place for ideas and general questions: https://github.com/tryAGI/Deepgram/discussions
Discord: https://discord.gg/Ca2xhfBf3v

Acknowledgments

JetBrains logo

This project is supported by JetBrains through the Open Source Support Program.