.NET SDK V3 to V4 Migration Guide

Migrating from Deepgram .NET SDK v3 to the Deepgram .NET SDK v4

This guide is for users with experience using the Deepgram .NET SDK v3 who want to migrate to the Deepgram .NET SDK v4. This is not an end-to-end guide, but a reference for people using our existing .NET SDK to migrate to our newest version.

Notable Changes

  • Significant Restructure of the .NET SDK
  • Improved Implementation for Live, PreRecorded, and Manage Clients
  • Implements Text-to-Speech API
  • Implements Intelligence APIs for PreRecorded and Text (Summary, Intent, Topic, Sentiment)
  • Support for self-hosted/on-prem (previously not supported)
  • Improved and Independent Timeout Capabilities per API Call
  • Verbosity Logging Levels for Troubleshooting
  • Custom Header and Query Parameters for API calls
  • Better Error Handling
  • Support for future products (APIs)

Migration Guide

This section of the migration guide focuses on the SDK’s PreRecorded and Live Clients. It will allow you to transition to the latest version of the SDK.

Installation

Terminal
1# The latest version will definitely be newer than version 4.0.0 listed below
2# Visit https://www.nuget.org/packages/Deepgram for the latest version available.
3dotnet add package Deepgram

Transcription: Pre-Recorded

There are two methods for transcribing Pre-Recorded audio:

  • Using a local file on the file system
  • Providing a URL pointing to an supported audio file

Local File Transcription

Transcribe a local file on the same filesystem as the app is running.

1var credentials = new Credentials(DEEPGRAM_API_KEY);
2
3var deepgramClient = new DeepgramClient(credentials);
4
5using (FileStream fs = File.OpenRead("path\\to\\file"))
6{
7 var response = await deepgramClient.Transcription.Prerecorded.GetTranscriptionAsync(
8 new StreamSource(
9 fs,
10 "audio/wav"),
11 new PrerecordedTranscriptionOptions()
12 {
13 Model = "nova-3",
14 });
15}

URL File Transcription

Transcribe a remote file by sending a publicly accessible URL.

1var credentials = new Credentials("YOUR API KEY");
2var deepgramClient = new DeepgramClient(credentials);
3
4var response = await deepgramClient.Transcription.Prerecorded.GetTranscriptionAsync(
5 new UrlSource("https://dpgr.am/bueller.wav"),
6 new PrerecordedTranscriptionOptions(){
7 Tier = "nova-3",
8 }
9);
10
11Console.WriteLine(JsonConvert.SerializeObject(response));

Transcription: Live

The Live Client abstracts the underlying WebSocket implementation from the user for greater usability. This in turn only requires that you deal with higher-level functions like Connect(), Send(), Stop() methods.

1var credentials = new Credentials(DEEPGRAM_API_KEY);
2
3var deepgramClient = new DeepgramClient(credentials);
4
5using (var deepgramLive = deepgramClient.CreateLiveTranscriptionClient())
6{
7 deepgramLive.TranscriptReceived += HandleTranscriptReceived;
8
9 // Connection opened so start sending audio.
10 async void HandleConnectionOpened(object? sender, ConnectionOpenEventArgs e)
11 {
12 byte[] buffer;
13
14 using (FileStream fs = File.OpenRead("path\\to\\file"))
15 {
16 buffer = new byte[fs.Length];
17 fs.Read(buffer, 0, (int)fs.Length);
18 }
19
20 var chunks = buffer.Chunk(1000);
21
22 foreach (var chunk in chunks)
23 {
24 deepgramLive.SendData(chunk);
25 await Task.Delay(50);
26 }
27
28 await deepgramLive.FinishAsync();
29 }
30
31 void HandleTranscriptReceived(object? sender, TranscriptReceivedEventArgs e)
32 {
33 if (e.Transcript.IsFinal && e.Transcript.Channel.Alternatives.First().Transcript.Length > 0) {
34 var transcript = e.Transcript;
35 Console.WriteLine($"[Speaker: {transcript.Channel.Alternatives.First().Words.First().Speaker}] {transcript.Channel.Alternatives.First().Transcript}");
36 }
37 }
38
39 var options = new LiveTranscriptionOptions()
40 {
41 Model = "nova-3"
42 };
43 await deepgramLive.StartConnectionAsync(options);
44
45 while (deepgramLive.State() == WebSocketState.Open) { }
46}

Management API

Below is a transition guide for using the Manage APIs.

Get all projects for a user

1var result = await deepgramClient.Projects.ListProjectsAsync();

See our API reference for more info.

Get a project

1var result = await deepgramClient.Projects.ListProjectAsync(projectId);

See our API reference for more info.

Update a project

1var project = new Project()
2{
3 Project = "projectId string",
4 Name = "New name for Project"
5}
6var result = await deepgramClient.Projects.UpdateProjectAsync(project);

See our API reference for more info.

Delete a project

1var result = await deepgramClient.Projects.DeleteProjectAsync(projectId);

See our API reference for more info.

Get all project key details

1var result = await deepgramClient.Keys.ListKeysAsync(projectId);

See our API reference for more info.

Get a project key

1var result = await deepgramClient.Keys.GetKeyAsync(projectId,keyId);

See our API reference for more info.

Create a project key

1var scopes = new string[]{"admin","member"};
2var result = await deepgramClient.Keys.CreateKeyAsync(projectId,comment,scopes);

See our API reference for more info.

Delete a project key

1var result = await deepgramClient.Keys.DeleteKeyAsync(projectId, keyId);

See our API reference for more info.

Get all project members

1var result = await deepgramClient.Projects.GetMembersScopesAsync(projectId,memberId);

See our API reference for more info.

Remove a project member

1var result = await deepgramClient.Projects.RemoveMemberAsync(projectId,memberId);

See our API reference for more info.

Get all scopes for a project member

1var result = await deepgramClient.Keys. GetMemberScopesAsync(projectId,memberId);

See our API reference for more info.

Update a scope for a project member

1var scopeOptions = new UpdateScopeOption(){Scope = "admin"};
2var result = await deepgramClient.Keys.UpdateScopeAsync(projectId,memberId,scopeOptions);

See our API reference for more info.

Get all usage requests for a project

1var listAllRequestOptions = new listAllRequestOptions()
2{
3 StartDateTime = DateTime.Now
4};
5var result = await deepgramClient.Usage.ListAllRequestsAsync(projectId,listAllRequestOptions);

See our API reference for more info.

Get a usage request for a project

1var result = await deepgramClient.Usage.GetUsageRequestAsync(projectId,requestId);

See our API reference for more info.

Get the project usage summary

1var getUsageSummmaryOptions = new GetUsageSummmaryOptions()
2{
3 StartDateTime = DateTime.Now
4}
5var result = await deepgramClient.Usage.GetUsageSummaryAsync(projectId,getUsageSummmaryOptions);

See our API reference for more info.

Get project usage fields

1var getUsageFieldsOptions = new getUsageFieldsOptions()
2{
3 StartDateTime = Datetime.Now
4}
5var result = await deepgramClient.Usage.GetUsageFieldsAsync(projectId,getUsageFieldsOptions);

See our API reference for more info.

New to v4

[NOTICE] There were several APIs that were previously unavailable in v3 of the .NET SDK but that are now available in the v4 release. These included:

  • Self-hosted (on-prem) APIs
  • Manage APIs for Balances and Invitations
  • Intelligence APIs (SITS) for Text and Audio
  • Text-to-Speech

Please refer to the examples in the examples folder at the root of the .NET SDK repository for implementation details.

Built with