Deepgram 1.3.1
See the version list below for details.
dotnet add package Deepgram --version 1.3.1
NuGet\Install-Package Deepgram -Version 1.3.1
<PackageReference Include="Deepgram" Version="1.3.1" />
paket add Deepgram --version 1.3.1
#r "nuget: Deepgram, 1.3.1"
// Install Deepgram as a Cake Addin #addin nuget:?package=Deepgram&version=1.3.1 // Install Deepgram as a Cake Tool #tool nuget:?package=Deepgram&version=1.3.1
Deepgram .NET SDK
Official .NET SDK for Deepgram's automated speech recognition APIs.
This SDK only supports hosted usage of api.deepgram.com.
To access the API you will need a Deepgram account. Sign up for free at signup.
Documentation
Full documentation of the .NET SDK can be found on the Deepgram Developer Portal.
You can learn more about the full Deepgram API at https://developers.deepgram.com.
Installation
To install the C# client library using NuGet:
Run the following command from your terminal in your projects directory:
dotnet add package Deepgram
Targeted Frameworks
- 6.0.0
- 5.0.0
- .NET Core 3.1
- .NET Standard 2.0
Configuration
To setup the configuration of the Deepgram Client you can do one of the following:
- Create a Deepgram Client instance and pass in credentials in the constructor.
var credentials = new Credentials(YOUR_DEEPGRAM_API_KEY);
var deepgramClient = new DeepgramClient(credentials);
Or
- Provide the Deepgram API key and optional API Url in
appsettings.json
:
{
"appSettings": {
"Deepgram.Api.Key": "YOUR_DEEPGRAM_API_KEY",
"Deepgram.Api.Uri": "api.deepgram.com"
}
}
Note: In the event multiple configuration files are found, the order of precedence is as follows:
* ```appsettings.json``` which overrides
* ```settings.json```
Or
- Access the Configuration instance and set the appropriate key in your code for example:
Configuration.Instance.Settings["appSettings:Deepgram.Api.Key"] = "YOUR_DEEPGRAM_API_KEY";
Configuration.Instance.Settings["appSettings:Deepgram.Api.Uri"] = "api.deepgram.com";
Examples
Sending a Remote File for Transcription
var credentials = new Credentials(DEEPGRAM_API_KEY);
var deepgramClient = new DeepgramClient(credentials);
var response = await deepgramClient.Transcription.Prerecorded.GetTranscriptionAsync(
new Deepgram.Transcription.UrlSource("https://static.deepgram.com/examples/Bueller-Life-moves-pretty-fast.wav"),
new Deepgram.Transcription.PrerecordedTranscriptionOptions()
{
Punctuate = true
});
Sending a Local File for Transcription
var credentials = new Credentials(DEEPGRAM_API_KEY);
var deepgramClient = new DeepgramClient(credentials);
using (FileStream fs = File.OpenRead("path\\to\\file"))
{
var response = await deepgramClient.Transcription.Prerecorded.GetTranscriptionAsync(
new Deepgram.Transcription.StreamSource(
fs,
"audio/wav"),
new Deepgram.Transcription.PrerecordedTranscriptionOptions()
{
Punctuate = true
});
}
Real-time Transcription
The example below demonstrates sending a pre-recorded audio to simulate a real-time stream of audio. In a real application, this type of audio is better handled using the pre-recorded transcription.
var credentials = new Credentials(DEEPGRAM_API_KEY);
var deepgramClient = new DeepgramClient(credentials);
using (var deepgramLive = deepgramClient.CreateLiveTranscriptionClient())
{
deepgramLive.ConnectionOpened += HandleConnectionOpened;
deepgramLive.ConnectionClosed += HandleConnectionClosed;
deepgramLive.ConnectionError += HandleConnectionError;
deepgramLive.TranscriptReceived += HandleTranscriptReceived;
// Connection opened so start sending audio.
async void HandleConnectionOpened(object? sender, ConnectionOpenEventArgs e)
{
byte[] buffer;
using (FileStream fs = File.OpenRead("path\\to\\file"))
{
buffer = new byte[fs.Length];
fs.Read(buffer, 0, (int)fs.Length);
}
var chunks = buffer.Chunk(1000);
foreach (var chunk in chunks)
{
deepgramLive.SendData(chunk);
await Task.Delay(50);
}
await deepgramLive.FinishAsync();
}
void HandleTranscriptReceived(object? sender, TranscriptReceivedEventArgs e)
{
if (e.Transcript.IsFinal && e.Transcript.Channel.Alternatives.First().Transcript.Length > 0) {
var transcript = e.Transcript;
Console.WriteLine($"[Speaker: {transcript.Channel.Alternatives.First().Words.First().Speaker}] {transcript.Channel.Alternatives.First().Transcript}");
}
}
void HandleConnectionClosed(object? sender, ConnectionClosedEventArgs e)
{
Console.Write("Connection Closed");
}
void HandleConnectionError(object? sender, ConnectionErrorEventArgs e)
{
Console.WriteLine(e.Exception.Message);
}
var options = new LiveTranscriptionOptions() { Punctuate = true, Diarize = true, Encoding = Deepgram.Common.AudioEncoding.Linear16 };
await deepgramLive.StartConnectionAsync(options);
while (deepgramLive.State() == WebSocketState.Open) { }
}
Logging
The Library uses Microsoft.Extensions.Logging to preform all of it's logging tasks. To configure
logging for your app simply create a new ILoggerFactory and call the LogProvider.SetLogFactory()
method to tell the Deepgram library how to log. For example, to log to the console with Serilog, you'd need to install the Serilog package with dotnet add package Serilog
and then do the following:
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Configuration;
using Deepgram.Logger;
using Serilog;
var log = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.Console(outputTemplate: "{Timestamp:HH:mm} [{Level}]: {Message}\n")
.CreateLogger();
var factory = new LoggerFactory();
factory.AddSerilog(log);
LogProvider.SetLogFactory(factory);
Development and Contributing
Interested in contributing? We ❤️ pull requests!
To make sure our community is safe for all, be sure to review and agree to our Code of Conduct. Then see the Contribution guidelines for more information.
Getting Help
We love to hear from you so if you have questions, comments or find a bug in the project, let us know! You can either:
- Open an issue on this repository
- Tweet at us! We're @DeepgramDevs on Twitter
Further Reading
Check out the Developer Documentation at https://developers.deepgram.com/
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 is compatible. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETCoreApp 3.1
- Microsoft.Extensions.Configuration (>= 6.0.1)
- Microsoft.Extensions.Configuration.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Configuration.Json (>= 6.0.0)
- Microsoft.Extensions.Logging (>= 6.0.0)
- Newtonsoft.Json (>= 13.0.1)
- System.Threading.Channels (>= 6.0.0)
-
.NETStandard 2.0
- Microsoft.Extensions.Configuration (>= 6.0.1)
- Microsoft.Extensions.Configuration.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Configuration.Json (>= 6.0.0)
- Microsoft.Extensions.Logging (>= 6.0.0)
- Newtonsoft.Json (>= 13.0.1)
- System.Threading.Channels (>= 6.0.0)
-
net5.0
- Microsoft.Extensions.Configuration (>= 6.0.1)
- Microsoft.Extensions.Configuration.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Configuration.Json (>= 6.0.0)
- Microsoft.Extensions.Logging (>= 6.0.0)
- Newtonsoft.Json (>= 13.0.1)
- System.Threading.Channels (>= 6.0.0)
-
net6.0
- Microsoft.Extensions.Configuration (>= 6.0.1)
- Microsoft.Extensions.Configuration.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Configuration.Json (>= 6.0.0)
- Microsoft.Extensions.Logging (>= 6.0.0)
- Newtonsoft.Json (>= 13.0.1)
- System.Threading.Channels (>= 6.0.0)
Version | Downloads | Last updated |
---|---|---|
4.4.0 | 520 | 11/4/2024 |
4.3.6 | 2,504 | 10/2/2024 |
4.3.5 | 259 | 9/27/2024 |
4.3.4 | 184 | 9/26/2024 |
4.3.3 | 141 | 9/24/2024 |
4.3.2 | 6,269 | 9/18/2024 |
4.2.0 | 3,194 | 8/14/2024 |
4.1.0 | 7,257 | 7/15/2024 |
4.0.3 | 4,019 | 7/9/2024 |
4.0.2 | 4,428 | 6/11/2024 |
4.0.1 | 9,537 | 4/24/2024 |
4.0.0 | 155 | 4/22/2024 |
3.4.2 | 12,047 | 3/29/2024 |
3.4.1 | 6,820 | 2/13/2024 |
3.4.0 | 33,531 | 9/26/2023 |
3.3.0 | 1,327 | 9/14/2023 |
3.2.0 | 752 | 8/28/2023 |
3.1.0 | 2,188 | 8/14/2023 |
2.2.0 | 11,207 | 7/20/2023 |
2.1.0 | 3,475 | 6/30/2023 |
2.0.0 | 8,430 | 4/12/2023 |
1.13.0 | 1,468 | 1/17/2023 |
1.12.0 | 808 | 12/13/2022 |
1.11.1 | 592 | 11/30/2022 |
1.10.0 | 2,275 | 11/15/2022 |
1.9.0 | 869 | 10/30/2022 |
1.8.0 | 742 | 10/6/2022 |
1.7.1 | 709 | 10/1/2022 |
1.7.0 | 687 | 9/27/2022 |
1.6.0 | 707 | 9/20/2022 |
1.5.1 | 727 | 9/2/2022 |
1.4.1 | 749 | 8/17/2022 |
1.4.0 | 766 | 7/14/2022 |
1.3.1 | 720 | 7/1/2022 |
1.2.0 | 820 | 4/20/2022 |
1.1.0 | 1,049 | 2/4/2022 |
1.0.0 | 618 | 12/20/2021 |
1.0.0-beta2 | 599 | 11/22/2021 |
1.0.0-beta1 | 676 | 11/21/2021 |