Skip to content

Commit

Permalink
Deepgram SDK v2.3.0 (#109)
Browse files Browse the repository at this point in the history
* updates to readme

* adds summarize v2

* adds NullValueHandling to ignore response null values

* example program.cs updated for remote and local file

* add Newtonsoft.json

* adds warning object

* adds warning

* formatting

* feat: filler_words for SDK v2

* fix: remove user agent from live client for SDK v2

---------

Co-authored-by: Brian Barrow <[email protected]>
Co-authored-by: John Vajda <[email protected]>
Co-authored-by: Sandra Rodgers <[email protected]>
Co-authored-by: Sandra Rodgers <[email protected]>
  • Loading branch information
5 people authored Aug 2, 2023
1 parent d6b3f57 commit 01ed28f
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 24 deletions.
1 change: 0 additions & 1 deletion Deepgram/Transcription/LiveTranscriptionClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public async Task StartConnectionAsync(LiveTranscriptionOptions options)

_clientWebSocket = new ClientWebSocket();
_clientWebSocket.Options.SetRequestHeader("Authorization", $"token {_credentials.ApiKey}");
_clientWebSocket.Options.SetRequestHeader("User-Agent", Helpers.GetUserAgent());

_tokenSource = new CancellationTokenSource();
try
Expand Down
6 changes: 6 additions & 0 deletions Deepgram/Transcription/LiveTranscriptionOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,5 +226,11 @@ public class LiveTranscriptionOptions
/// </summary>
[JsonProperty("sample_rate")]
public Nullable<int> SampleRate { get; set; } = null;

/// <summary>
/// Indicates whether Deepgram should detect topics within the provided audio.
/// </summary>
[JsonProperty("filler_words")]
public Nullable<bool> FillerWords { get; set; } = null;
}
}
8 changes: 7 additions & 1 deletion Deepgram/Transcription/PrerecordedTranscriptionMetaData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public class PrerecordedTranscriptionMetaData
/// Number of channels detected in the submitted audio.
/// </summary>
[JsonProperty("channels")]
public int Channels { get; set; }
public int Channels { get; set; }

/// <summary>
/// Warnings to provide feedback about unsupported and deprecated queries.
/// </summary>
[JsonProperty("warnings")]
public Warning[] Warnings { get; set; }
}
}
8 changes: 7 additions & 1 deletion Deepgram/Transcription/PrerecordedTranscriptionOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public class PrerecordedTranscriptionOptions
/// Indicates whether Deepgram should provide summarizations of sections of the provided audio.
/// </summary>
[JsonProperty("summarize")]
public Nullable<bool> Summarize { get; set; } = null;
public object Summarize { get; set; } = null;

/// <summary>
/// Indicates whether Deepgram should detect entities within the provided audio.
Expand Down Expand Up @@ -242,5 +242,11 @@ public class PrerecordedTranscriptionOptions
/// </summary>
[JsonProperty("sentiment_threshold")]
public Nullable<decimal> SentimentThreshold { get; set; } = null;

/// <summary>
/// Indicates whether Deepgram should detect topics within the provided audio.
/// </summary>
[JsonProperty("filler_words")]
public Nullable<bool> FillerWords { get; set; } = null;
}
}
6 changes: 6 additions & 0 deletions Deepgram/Transcription/PrerecordedTranscriptionResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,11 @@ public class PrerecordedTranscriptionResult
/// </summary>
[JsonProperty("utterances")]
public Utterance[] Utterances { get; set; }

/// <summary>
/// Summary of Transcription.
/// </summary>
[JsonProperty("summary", NullValueHandling=NullValueHandling.Ignore)]
public Summary Summary { get; set; }
}
}
10 changes: 9 additions & 1 deletion Deepgram/Transcription/Summary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class Summary
/// <summary>
/// Summary of a section of the transcript
/// </summary>
[JsonProperty("summary")]
[JsonProperty("summary", NullValueHandling=NullValueHandling.Ignore)]
public string TextSummary { get; set; }

/// <summary>
Expand All @@ -23,5 +23,13 @@ public class Summary
[JsonProperty("end_word")]
public int EndWord { get; set; }

/// <summary>
/// Array of Channel objects.
/// </summary>
[JsonProperty("short", NullValueHandling=NullValueHandling.Ignore)]
public string Short { get; set; }

}
}


31 changes: 31 additions & 0 deletions Deepgram/Transcription/Warning.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Deepgram.Transcription
{
public class Warning
{
/// <summary>
/// Parameter sent in the request that resulted in the warning
/// </summary>
[JsonProperty("parameter")]
public string Parameter { get; set; }

/// <summary>
/// The type of warning
/// </summary>
[JsonProperty("type")]
[JsonConverter(typeof(StringEnumConverter))]
public WarningType Type { get; set; }

/// <summary>
/// The warning message
/// </summary>
[JsonProperty("message")]
public string Message { get; set; }

}
}


23 changes: 23 additions & 0 deletions Deepgram/Transcription/WarningType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Runtime.Serialization;

namespace Deepgram.Transcription
{
public enum WarningType

{
[EnumMember(Value = "unsupported_language")]
UnsupportedLanguage,

[EnumMember(Value = "unsupported_model")]
UnsupportedModel,

[EnumMember(Value = "unsupported_encoding")]
UnsupportedEncoding,

[EnumMember(Value = "deprecated")]
Deprecated
}
}


26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

[![Nuget](https://img.shields.io/nuget/v/deepgram)](https://www.nuget.org/packages/Deepgram) [![Build Status](https://github.com/deepgram-devs/deepgram-dotnet-sdk/workflows/CI/badge.svg)](https://github.com/deepgram-devs/deepgram-dotnet-sdk/actions?query=CI) [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg)](./.github/CODE_OF_CONDUCT.md)

Official .NET SDK for [Deepgram](https://www.deepgram.com/)'s automated
speech recognition APIs.
Official .NET SDK for [Deepgram](https://www.deepgram.com/). Start building with our powerful transcription & speech understanding API.

To access the API you will need a Deepgram account. Sign up for free at
[signup](https://console.deepgram.com/signup?utm_medium=github&utm_source=devrel&utm_content=dotnet-sdk).
> This SDK only supports hosted usage of api.deepgram.com.
## Getting an API Key

🔑 To access the Deepgram API you will need a [free Deepgram API Key](https://console.deepgram.com/signup?jump=keys).

## Documentation

Full documentation of the .NET SDK can be found on the
[Deepgram Developer Portal](https://developers.deepgram.com/sdks-tools/sdks/dotnet-sdk/).
Complete documentation of the .NET SDK can be found on the
[Deepgram Docs](https://developers.deepgram.com/docs/dotnet-sdk).

You can learn more about the full Deepgram API at [https://developers.deepgram.com](https://developers.deepgram.com).

Expand Down Expand Up @@ -151,7 +153,7 @@ using (var deepgramLive = deepgramClient.CreateLiveTranscriptionClient())

void HandleTranscriptReceived(object? sender, TranscriptReceivedEventArgs e)
{
if (e.Transcript.IsFinal && e.Transcript.Channel.Alternatives.First().Transcript.Length > 0) {
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}");
}
Expand Down Expand Up @@ -208,11 +210,9 @@ To make sure our community is safe for all, be sure to review and agree to our
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](https://github.com/deepgram-devs/deepgram-dotnet-sdk/issues/new) on this repository
- Tweet at us! We're [@DeepgramAI on Twitter](https://twitter.com/DeepgramAI)

## Further Reading
- [Open an issue in this repository](https://github.com/deepgram-devs/deepgram-dotnet-sdk/issues/new)
- [Join the Deepgram Github Discussions Community](https://github.com/orgs/deepgram/discussions)
- [Join the Deepgram Discord Community](https://discord.gg/xWRaCDBtW4)

Check out the Developer Documentation at [https://developers.deepgram.com/](https://developers.deepgram.com/)

[signup]: https://console.deepgram.com?utm_source=dotnet-sdk&utm_content=readme
[license]: LICENSE.txt
12 changes: 6 additions & 6 deletions SampleApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
using Deepgram.Transcription;
using Newtonsoft.Json;

namespace SampleApp
{
class Program
{
const string API_KEY = "DEEPGRAM_API_KEY";
const string API_KEY = "";

static async Task Main(string[] args)
{
DeepgramClient deepgram = new DeepgramClient(new Credentials(API_KEY));
var response = await deepgram.Transcription.Prerecorded.GetTranscriptionAsync(
new UrlSource("https://static.deepgram.com/examples/Bueller-Life-moves-pretty-fast.wav"),
new UrlSource("https://www.happyhourspanish.com/wp-content/uploads/podcasts/HHS_Podcast_Soccer_Eurocup.mp3"),
new PrerecordedTranscriptionOptions()
{
Punctuate = true,
Utterances = true,
Redaction = new [] { "pci", "ssn" }
Summarize = "v2",
DetectLanguage = true
});

Console.Write(response.ToWebVTT());
Console.WriteLine(JsonConvert.SerializeObject(response));
}
}
}
5 changes: 4 additions & 1 deletion SampleApp/SampleApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand All @@ -13,5 +13,8 @@
<ItemGroup>
<Using Include="Deepgram" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

</Project>
Binary file added SampleApp/preamble.wav
Binary file not shown.

0 comments on commit 01ed28f

Please sign in to comment.