deepgram-dotnet-voice-agent

Используйте при написании или рецензировании кода на C# в этом репозитории, который создаёт интерактивный голосовой агент Deepgram через WebSocket. Охватывает…

npx skills add https://github.com/deepgram/deepgram-dotnet-sdk --skill deepgram-dotnet-voice-agent

Using Deepgram Voice Agent (.NET SDK)

Full-duplex voice agent sessions over a single WebSocket.

Use a different skill when:

  • One-way transcription → deepgram-dotnet-speech-to-text or deepgram-dotnet-conversational-stt.
  • One-way synthesis → deepgram-dotnet-text-to-speech.
  • Admin APIs → deepgram-dotnet-management-api.

Authentication

dotnet add package Deepgram
dotnet add package Deepgram.Microphone   # only if you need local mic capture
using Deepgram;

Deepgram.Library.Initialize();
// Uses DEEPGRAM_API_KEY env var; pass apiKey: "..." to override
var agentClient = ClientFactory.CreateAgentWebSocketClient();

Quick start

using Deepgram.Models.Agent.v2.WebSocket;

var agentClient = ClientFactory.CreateAgentWebSocketClient();

await agentClient.Subscribe(new EventHandler<ConversationTextResponse>((sender, e) =>
{
    Console.WriteLine(e);
}));

await agentClient.Subscribe(new EventHandler<AudioResponse>((sender, e) =>
{
    if (e.Stream != null)
    {
        // Raw linear16 PCM — see examples/agent/websocket/no_mic/Program.cs for WAV header.
        using var writer = new BinaryWriter(File.Open("output.raw", FileMode.Append));
        writer.Write(e.Stream.ToArray());
    }
}));

var settings = new SettingsSchema();
settings.Agent.Think.Provider.Type = "open_ai";
settings.Agent.Think.Provider.Model = "gpt-4o-mini";
settings.Agent.Greeting = "Hello! How can I help you today?";
settings.Agent.Listen.Provider.Type = "deepgram";
settings.Agent.Listen.Provider.Model = "nova-3";
settings.Agent.Speak.Provider.Type = "deepgram";
settings.Agent.Speak.Provider.Model = "aura-2-thalia-en";
settings.Audio.Input.Encoding = "linear16";
settings.Audio.Input.SampleRate = 24000;
settings.Audio.Output.Encoding = "linear16";
settings.Audio.Output.SampleRate = 24000;

bool connected = await agentClient.Connect(settings);
if (!connected)
{
    Console.Error.WriteLine("Agent WebSocket connection failed — check API key and network.");
    return;
}

await agentClient.SendInjectUserMessage("Say hello in one sentence.");

// Cleanup when done
Console.ReadKey();
await agentClient.Stop();

Streaming microphone audio

var microphone = new Microphone(
    push_callback: (audioData, length) =>
    {
        byte[] chunk = new byte[length];
        Array.Copy(audioData, chunk, length);
        agentClient.SendBinary(chunk);
    },
    rate: 24000,
    channels: 1,
    format: SampleFormat.Int16);

microphone.Start();

// Cleanup
Console.ReadKey();
microphone.Stop();
await agentClient.Stop();

Key params and events

Settings models:

  • SettingsSchema
  • Audio, Input, Output
  • Agent, Listen, Think, Speak
  • Provider (dynamic extra properties supported)

Important events:

  • ConversationTextResponse
  • AudioResponse
  • AgentStartedSpeakingResponse
  • AgentAudioDoneResponse
  • AgentThinkingResponse
  • UserStartedSpeakingResponse
  • FunctionCallRequestResponse
  • SettingsAppliedResponse

Send helpers:

  • SendInjectUserMessage(string)
  • SendInjectUserMessage(InjectUserMessageSchema)
  • SendBinary(...)
  • SendBinaryImmediately(...)
  • SendKeepAlive()

References

Gotchas

  1. Use the actual event/model names in this repo. SettingsSchema, ConversationTextResponse, etc. — not the Python names.
  2. Provider is dynamic. Extra provider-specific properties are stored through JsonExtensionData; set them carefully.
  3. Function call support is partial. FunctionCallRequestResponse is marked TODO: this needs to be defined, so inspect raw payload behavior before relying on typed fields.
  4. There is no convenience SendFunctionCallResponse(...) helper on the public interface. If you need it, send serialized FunctionCallResponseSchema manually via the generic send path.
  5. Audio formats must match. The examples align both input and output around linear16 / 24000.
  6. Deepgram.Microphone depends on PortAudio. Local microphone examples need the helper project/package and a working PortAudio environment.

Example files in this repo

  • examples/agent/websocket/simple/Program.cs
  • examples/agent/websocket/no_mic/Program.cs
  • examples/agent/websocket/arbitrary_keys/Program.cs

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

Больше skills от deepgram

deepclaw-voice
deepgram
Настройка телефонных звонков в OpenClaw с помощью Deepgram Voice Agent API
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
Используйте при оценке, расширении или написании кода на C# для конверсационного распознавания речи, потоковой транскрипции в стиле Flux или потоковой передачи с чередованием реплик в…
official
deepgram-dotnet-management-api
deepgram
Используйте при написании или рецензировании C# кода в этом репозитории, который вызывает Deepgram Management API для проектов, моделей, ключей, участников, приглашений, использования, балансов и…
official
deepgram-dotnet-speech-to-text
deepgram
Используйте при написании или рецензировании кода на C# в этом репозитории, который вызывает Deepgram Speech-to-Text для транскрипции предварительно записанного или живого аудио. Охватывает…
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