Skip to content

Commit

Permalink
Merge pull request #345 from dvonthenen/auto-flush-deadlock-plus-refa…
Browse files Browse the repository at this point in the history
…ctor

Fix Deadlock, Bumped Interface on WS Clients, Consolidated WS Code
davidvonthenen authored Nov 1, 2024
2 parents cc81602 + 22518be commit ba0f717
Showing 106 changed files with 7,222 additions and 1,138 deletions.
20 changes: 20 additions & 0 deletions Deepgram.Dev.sln
Original file line number Diff line number Diff line change
@@ -169,6 +169,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "reconnect_same_object", "re
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReconnectStreaming", "tests\edge_cases\reconnect_same_object\ReconnectStreaming.csproj", "{64AB4BAC-6917-424D-A5EA-BA023BD7795A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "stt_v1_client_example", "stt_v1_client_example", "{0BF29CA2-1CD6-4FF0-BC7B-B33C6B41E9A1}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tts_v1_client_example", "tts_v1_client_example", "{5CEEB2F0-F284-4BB3-8999-6E91151C0C06}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Streaming", "tests\edge_cases\stt_v1_client_example\Streaming.csproj", "{964A87B4-31F8-4D68-AE64-64E66C9959FD}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Speak", "tests\edge_cases\tts_v1_client_example\Speak.csproj", "{AB053DDA-2487-476C-9793-A50C37F10CCA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -311,6 +319,14 @@ Global
{64AB4BAC-6917-424D-A5EA-BA023BD7795A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{64AB4BAC-6917-424D-A5EA-BA023BD7795A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{64AB4BAC-6917-424D-A5EA-BA023BD7795A}.Release|Any CPU.Build.0 = Release|Any CPU
{964A87B4-31F8-4D68-AE64-64E66C9959FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{964A87B4-31F8-4D68-AE64-64E66C9959FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{964A87B4-31F8-4D68-AE64-64E66C9959FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{964A87B4-31F8-4D68-AE64-64E66C9959FD}.Release|Any CPU.Build.0 = Release|Any CPU
{AB053DDA-2487-476C-9793-A50C37F10CCA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AB053DDA-2487-476C-9793-A50C37F10CCA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AB053DDA-2487-476C-9793-A50C37F10CCA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AB053DDA-2487-476C-9793-A50C37F10CCA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -392,6 +408,10 @@ Global
{ECB0B55E-54C1-4723-8641-9249E7507FB0} = {2F92D959-D3C7-4EFF-8549-C6162E517644}
{6E328CB9-8C9B-446B-B83E-3796804497F7} = {1280E66D-A375-422A-ACB4-48F17E9C190E}
{64AB4BAC-6917-424D-A5EA-BA023BD7795A} = {6E328CB9-8C9B-446B-B83E-3796804497F7}
{0BF29CA2-1CD6-4FF0-BC7B-B33C6B41E9A1} = {1280E66D-A375-422A-ACB4-48F17E9C190E}
{5CEEB2F0-F284-4BB3-8999-6E91151C0C06} = {1280E66D-A375-422A-ACB4-48F17E9C190E}
{964A87B4-31F8-4D68-AE64-64E66C9959FD} = {0BF29CA2-1CD6-4FF0-BC7B-B33C6B41E9A1}
{AB053DDA-2487-476C-9793-A50C37F10CCA} = {5CEEB2F0-F284-4BB3-8999-6E91151C0C06}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8D4ABC6D-7126-4EE2-9303-43A954616B2A}
1 change: 1 addition & 0 deletions Deepgram.Tests/Fakes/ConcreteRestClient.cs
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
// SPDX-License-Identifier: MIT

using Deepgram.Models.Authenticate.v1;
using Deepgram.Abstractions.v1;

namespace Deepgram.Tests.Fakes;

Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@
using Deepgram.Models.Authenticate.v1;
using Deepgram.Models.Manage.v1;
using Deepgram.Models.PreRecorded.v1;
using Deepgram.Models.Exceptions.v1;

using Deepgram.Clients.Manage.v1;

1 change: 1 addition & 0 deletions Deepgram.Tests/UnitTests/ClientTests/AnalyzeClientTests.cs
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
using Deepgram.Models.Authenticate.v1;
using Deepgram.Clients.Analyze.v1;
using Deepgram.Models.Analyze.v1;
using Deepgram.Abstractions.v1;

namespace Deepgram.Tests.UnitTests.ClientTests;

3 changes: 1 addition & 2 deletions Deepgram.Tests/UnitTests/ClientTests/ManageClientTest.cs
Original file line number Diff line number Diff line change
@@ -5,8 +5,7 @@
using Deepgram.Models.Authenticate.v1;
using Deepgram.Models.Manage.v1;
using Deepgram.Clients.Manage.v1;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection;
using NSubstitute;
using Deepgram.Abstractions.v1;

namespace Deepgram.Tests.UnitTests.ClientTests;

1 change: 1 addition & 0 deletions Deepgram.Tests/UnitTests/ClientTests/OnPremClientTests.cs
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
using Deepgram.Models.Authenticate.v1;
using Deepgram.Models.SelfHosted.v1;
using Deepgram.Clients.SelfHosted.v1;
using Deepgram.Abstractions.v1;

namespace Deepgram.Tests.UnitTests.ClientTests;

Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
using Deepgram.Models.Authenticate.v1;
using Deepgram.Clients.Listen.v1.REST;
using Deepgram.Models.Listen.v1.REST;
using Deepgram.Abstractions.v1;

namespace Deepgram.Tests.UnitTests.ClientTests;

1 change: 1 addition & 0 deletions Deepgram.Tests/UnitTests/ClientTests/SpeakClientTests.cs
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
using Deepgram.Models.Authenticate.v1;
using Deepgram.Models.Speak.v1.REST;
using Deepgram.Clients.Speak.v1.REST;
using Deepgram.Abstractions.v1;

namespace Deepgram.Tests.UnitTests.ClientTests;

Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
// SPDX-License-Identifier: MIT

using Deepgram.Models.Manage.v1;
using Deepgram.Abstractions;
using Deepgram.Abstractions.v1;

namespace Deepgram.Tests.UnitTests.UtilitiesTests;

15 changes: 0 additions & 15 deletions Deepgram/Abstractions/LocalFileWithMetadata.cs

This file was deleted.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Abstractions;
namespace Deepgram.Abstractions.v1;

/// <summary>
/// Defaults for the REST Client
33 changes: 33 additions & 0 deletions Deepgram/Abstractions/v1/LocalFileWithMetadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Abstractions.v1;

/// <summary>
/// LocalFileWithMetadata is a class that represents a file with metadata.
/// </summary>
public class LocalFileWithMetadata
{
/// <summary>
/// Gets or sets the metadata associated with the file content.
/// </summary>
public Dictionary<string, string> Metadata { get; set; }

/// <summary>
/// Gets or sets the file content as a MemoryStream.
/// The caller is responsible for disposing of this stream when no longer needed.
/// </summary>
/// <remarks>
/// This property should be properly disposed of to prevent memory leaks.
/// </remarks>
public MemoryStream Content { get; set; }

/// <summary>
/// Releases the resources used by the Content stream.
/// </summary>
public void Dispose()
{
Content?.Dispose();
}
}
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Abstractions;
namespace Deepgram.Abstractions.v1;

/// <summary>
/// Just a NoopSchema where you dont need to marshall JSON into a Async function.
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Abstractions;
namespace Deepgram.Abstractions.v1;

/// <summary>
/// Helper funcitons for HttpRequests
783 changes: 783 additions & 0 deletions Deepgram/Abstractions/v2/AbstractRestClient.cs

Large diffs are not rendered by default.

766 changes: 766 additions & 0 deletions Deepgram/Abstractions/v2/AbstractWebSocketClient.cs

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions Deepgram/Abstractions/v2/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Abstractions.v2;

/// <summary>
/// Defaults for the REST and WS AbstractClient
/// </summary>
public static class Constants
{
// For REST
public const int OneSecond = 1000;
public const int OneMinute = 60 * OneSecond;
public const int DefaultRESTTimeout = 30 * OneSecond;

// For WS
public const int BufferSize = 1024 * 16;
public const int UseArrayLengthForSend = -1;

public const int DefaultConnectTimeout = 5000;
public const int DefaultDisconnectTimeout = 5000;
}

33 changes: 33 additions & 0 deletions Deepgram/Abstractions/v2/LocalFileWithMetadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Abstractions.v2;

/// <summary>
/// LocalFileWithMetadata is a class that represents a file with metadata.
/// </summary>
public class LocalFileWithMetadata : IDisposable
{
/// <summary>
/// Gets or sets the metadata associated with the file content.
/// </summary>
public Dictionary<string, string> Metadata { get; set; }

/// <summary>
/// Gets or sets the file content as a MemoryStream.
/// The caller is responsible for disposing of this stream when no longer needed.
/// </summary>
/// <remarks>
/// This property should be properly disposed of to prevent memory leaks.
/// </remarks>
public MemoryStream Content { get; set; }

/// <summary>
/// Releases the resources used by the Content stream.
/// </summary>
public void Dispose()
{
Content?.Dispose();
}
}
13 changes: 13 additions & 0 deletions Deepgram/Abstractions/v2/NoopSchema.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Abstractions.v2;

/// <summary>
/// Just a NoopSchema where you dont need to marshall JSON into a Async function.
/// </summary>
public class NoopSchema
{
}

61 changes: 61 additions & 0 deletions Deepgram/Abstractions/v2/Utilities.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2021-2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Abstractions.v2;

/// <summary>
/// Helper funcitons for HttpRequests
/// </summary>
internal static class HttpRequestUtil
{
public const string DEFAULT_CONTENT_TYPE = "application/json";

static readonly JsonSerializerOptions _jsonSerializerOptions = new()
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
NumberHandling = JsonNumberHandling.AllowReadingFromString,
};

/// <summary>
/// Create the body payload of a HttpRequestMessage
/// </summary>
/// <typeparam name="T">Type of the body to be sent</typeparam>
/// <param name="body">instance value for the body</param>
/// <param name="contentType">What type of content is being sent default is : application/json</param>
/// <returns></returns>
internal static StringContent CreatePayload<T>(T body)
{
var serialized = JsonSerializer.Serialize(body, _jsonSerializerOptions);
return new(serialized, Encoding.UTF8, DEFAULT_CONTENT_TYPE);
}


/// <summary>
/// Create the stream payload of a HttpRequestMessage
/// </summary>
/// <param name="body">of type stream</param>
/// <returns>HttpContent</returns>
internal static HttpContent CreateStreamPayload(Stream body)
{
body.Seek(0, SeekOrigin.Begin);
HttpContent httpContent = new StreamContent(body);
httpContent.Headers.Add("Content-Length", body.Length.ToString());
return httpContent;
}


/// <summary>
/// method that deserializes DeepgramResponse and performs null checks on values
/// </summary>
/// <typeparam name="TResponse">Class Type of expected response</typeparam>
/// <param name="httpResponseMessage">Http Response to be deserialized</param>
/// <returns>instance of TResponse or a Exception</returns>
internal static async Task<TResponse> DeserializeAsync<TResponse>(HttpResponseMessage httpResponseMessage)
{
var content = await httpResponseMessage.Content.ReadAsStringAsync();
var deepgramResponse = JsonSerializer.Deserialize<TResponse>(content);
return deepgramResponse;
}

}
32 changes: 32 additions & 0 deletions Deepgram/Abstractions/v2/WebSocketMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2021-2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Abstractions.v2;

internal readonly struct WebSocketMessage
{
public WebSocketMessage(byte[] message, WebSocketMessageType type)
: this(message, type, Constants.UseArrayLengthForSend)
{
}

public WebSocketMessage(byte[] message, WebSocketMessageType type, int length)
{
if (length != Constants.UseArrayLengthForSend && length <= message.Length && length > 0)
{
Message = new ArraySegment<byte>(message, 0, length);
}
else
{
Message = new ArraySegment<byte>(message, 0, message.Length);
}
MessageType = type;
}

public int Length => Message.Count;

public ArraySegment<byte> Message { get; }

public WebSocketMessageType MessageType { get; }
}
115 changes: 102 additions & 13 deletions Deepgram/ClientFactory.cs
Original file line number Diff line number Diff line change
@@ -3,7 +3,13 @@
// SPDX-License-Identifier: MIT

using Deepgram.Models.Authenticate.v1;
using Deepgram.Clients.Interfaces.v1;
using V1 = Deepgram.Clients.Interfaces.v1;
using V2 = Deepgram.Clients.Interfaces.v2;

using ListenV1 = Deepgram.Clients.Listen.v1.WebSocket;
using ListenV2 = Deepgram.Clients.Listen.v2.WebSocket;
using SpeakV1 = Deepgram.Clients.Speak.v1.WebSocket;
using SpeakV2 = Deepgram.Clients.Speak.v2.WebSocket;

namespace Deepgram;

@@ -16,11 +22,20 @@
/// <param name="options"></param>
/// <param name="httpId"></param>
/// <returns></returns>
public static IAnalyzeClient CreateAnalyzeClient(string apiKey = "", DeepgramHttpClientOptions? options = null, string? httpId = null)
public static V1.IAnalyzeClient CreateAnalyzeClient(string apiKey = "", DeepgramHttpClientOptions? options = null, string? httpId = null)
{
return new AnalyzeClient(apiKey, options, httpId);
}

/// <summary>
/// This method allows you to create an AnalyzeClient with a specific version of the client.
/// </summary>
public static object CreateAnalyzeClient(int version, string apiKey = "", DeepgramHttpClientOptions? options = null, string? httpId = null)
{
// Currently only a single version of the AnalyzeClient exists
return new AnalyzeClient(apiKey, options, httpId);
}

/// <summary>
// *********** WARNING ***********
// This function creates a LiveClient for the Deepgram API
@@ -32,31 +47,59 @@
// *********** WARNING ***********
/// </summary>
[Obsolete("Please use CreateListenWebSocketClient instead", false)]
public static ILiveClient CreateLiveClient(string apiKey = "", DeepgramWsClientOptions? options = null)
public static V1.ILiveClient CreateLiveClient(string apiKey = "", DeepgramWsClientOptions? options = null)
{
return new LiveClient(apiKey, options);
}

/// <summary>
/// Create a new ListenWebSocketClient
/// Create a new ListenWebSocketClient using the latest version
/// </summary>
/// <param name="apiKey"></param>
/// <param name="options"></param>
/// <returns></returns>
public static IListenWebSocketClient CreateListenWebSocketClient(string apiKey = "", DeepgramWsClientOptions? options = null)
public static V2.IListenWebSocketClient CreateListenWebSocketClient(string apiKey = "", DeepgramWsClientOptions? options = null)
{
return new ListenWebSocketClient(apiKey, options);
}

/// <summary>
/// This method allows you to create an AnalyzeClient with a specific version of the client.
/// </summary>
public static object CreateListenWebSocketClient(int version, string apiKey = "", DeepgramWsClientOptions? options = null)
{
// at some point this needs to be changed to use reflection to get the type of the client
switch(version)
{
case 1:
Log.Information("ClientFactory", $"Version 1 of the ListenWebSocketClient is being deprecated in the next major version.");
Log.Information("ClientFactory", $"Transition to the latest version at your earliest convenience.");
return new ListenV1.Client(apiKey, options);

Check warning on line 77 in Deepgram/ClientFactory.cs

GitHub Actions / test (6.0.x)

'Client' is obsolete: 'Please use Deepgram.Clients.Listen.v2.WebSocket instead'

Check warning on line 77 in Deepgram/ClientFactory.cs

GitHub Actions / build

'Client' is obsolete: 'Please use Deepgram.Clients.Listen.v2.WebSocket instead'

Check warning on line 77 in Deepgram/ClientFactory.cs

GitHub Actions / test (7.0.x)

'Client' is obsolete: 'Please use Deepgram.Clients.Listen.v2.WebSocket instead'

Check warning on line 77 in Deepgram/ClientFactory.cs

GitHub Actions / test (8.0.x)

'Client' is obsolete: 'Please use Deepgram.Clients.Listen.v2.WebSocket instead'
case 2:
return new ListenV2.Client(apiKey, options);
default:
throw new ArgumentException("Invalid version", nameof(version));
}
}

/// <summary>
/// Create a new ManageClient
/// </summary>
/// <param name="apiKey"></param>
/// <param name="options"></param>
/// <param name="httpId"></param>
/// <returns></returns>
public static IManageClient CreateManageClient(string apiKey = "", DeepgramHttpClientOptions? options = null, string? httpId = null)
public static V1.IManageClient CreateManageClient(string apiKey = "", DeepgramHttpClientOptions? options = null, string? httpId = null)
{
return new ManageClient(apiKey, options, httpId);
}

/// <summary>
/// This method allows you to create an ManageClient with a specific version of the client.
/// </summary>
public static object CreateManageClient(int version, string apiKey = "", DeepgramHttpClientOptions? options = null, string? httpId = null)
{
// Currently only a single version of the ManageClient exists
return new ManageClient(apiKey, options, httpId);
}

@@ -71,7 +114,7 @@
// *********** WARNING ***********
/// </summary>
[Obsolete("Please use CreateSelfHostedClient instead", false)]
public static IOnPremClient CreateOnPremClient(string apiKey = "", DeepgramHttpClientOptions? options = null, string? httpId = null)
public static V1.IOnPremClient CreateOnPremClient(string apiKey = "", DeepgramHttpClientOptions? options = null, string? httpId = null)
{
return new OnPremClient(apiKey, options, httpId);
}
@@ -83,11 +126,20 @@
/// <param name="options"></param>
/// <param name="httpId"></param>
/// <returns></returns>
public static ISelfHostedClient CreateSelfHostedClient(string apiKey = "", DeepgramHttpClientOptions? options = null, string? httpId = null)
public static V1.ISelfHostedClient CreateSelfHostedClient(string apiKey = "", DeepgramHttpClientOptions? options = null, string? httpId = null)
{
return new SelfHostedClient(apiKey, options, httpId);
}

/// <summary>
/// This method allows you to create an SelfHostedClient with a specific version of the client.
/// </summary>
public static object CreateSelfHostedClient(int version, string apiKey = "", DeepgramHttpClientOptions? options = null, string? httpId = null)
{
// Currently only a single version of the SelfHostedClient exists
return new SelfHostedClient(apiKey, options, httpId);
}

/// <summary>
// *********** WARNING ***********
// This function creates a PreRecordedClient for the Deepgram API
@@ -99,7 +151,7 @@
// *********** WARNING ***********
/// </summary>
[Obsolete("Please use CreateListenRESTClient instead", false)]
public static IPreRecordedClient CreatePreRecordedClient(string apiKey = "", DeepgramHttpClientOptions? options = null, string? httpId = null)
public static V1.IPreRecordedClient CreatePreRecordedClient(string apiKey = "", DeepgramHttpClientOptions? options = null, string? httpId = null)
{
return new PreRecordedClient(apiKey, options, httpId);
}
@@ -111,8 +163,17 @@
/// <param name="options"></param>
/// <param name="httpId"></param>
/// <returns></returns>
public static IListenRESTClient CreateListenRESTClient(string apiKey = "", DeepgramHttpClientOptions? options = null, string? httpId = null)
public static V1.IListenRESTClient CreateListenRESTClient(string apiKey = "", DeepgramHttpClientOptions? options = null, string? httpId = null)
{
return new ListenRESTClient(apiKey, options, httpId);
}

/// <summary>
/// This method allows you to create an ListenRESTClient with a specific version of the client.
/// </summary>
public static object CreateListenRESTClient(int version, string apiKey = "", DeepgramHttpClientOptions? options = null, string? httpId = null)
{
// Currently only a single version of the ListenRESTClient exists
return new ListenRESTClient(apiKey, options, httpId);
}

@@ -127,7 +188,7 @@
// *********** WARNING ***********
/// </summary>
[Obsolete("Please use CreateSpeakRESTClient instead", false)]
public static ISpeakClient CreateSpeakClient(string apiKey = "", DeepgramHttpClientOptions? options = null, string? httpId = null)
public static V1.ISpeakClient CreateSpeakClient(string apiKey = "", DeepgramHttpClientOptions? options = null, string? httpId = null)
{
return new SpeakClient(apiKey, options, httpId);
}
@@ -139,8 +200,17 @@
/// <param name="options"></param>
/// <param name="httpId"></param>
/// <returns></returns>
public static ISpeakRESTClient CreateSpeakRESTClient(string apiKey = "", DeepgramHttpClientOptions? options = null, string? httpId = null)
public static V1.ISpeakRESTClient CreateSpeakRESTClient(string apiKey = "", DeepgramHttpClientOptions? options = null, string? httpId = null)
{
return new SpeakRESTClient(apiKey, options, httpId);
}

/// <summary>
/// This method allows you to create an SpeakRESTClient with a specific version of the client.
/// </summary>
public static object CreateSpeakRESTClient(int version, string apiKey = "", DeepgramHttpClientOptions? options = null, string? httpId = null)
{
// Currently only a single version of the SpeakRESTClient exists
return new SpeakRESTClient(apiKey, options, httpId);
}

@@ -150,8 +220,27 @@
/// <param name="apiKey"></param>
/// <param name="options"></param>
/// <returns></returns>
public static ISpeakWebSocketClient CreateSpeakWebSocketClient(string apiKey = "", DeepgramWsClientOptions? options = null)
public static V2.ISpeakWebSocketClient CreateSpeakWebSocketClient(string apiKey = "", DeepgramWsClientOptions? options = null)
{
return new SpeakWebSocketClient(apiKey, options);
}

/// <summary>
/// This method allows you to create an SpeakWebSocketClient with a specific version of the client.
/// </summary>
public static object CreateSpeakWebSocketClient(int version, string apiKey = "", DeepgramHttpClientOptions? options = null)
{
// at some point this needs to be changed to use reflection to get the type of the client
switch (version)
{
case 1:
Log.Information("ClientFactory", $"Version 1 of the ListenWebSocketClient is being deprecated in the next major version.");
Log.Information("ClientFactory", $"Transition to the latest version at your earliest convenience.");
return new SpeakV1.Client(apiKey, options);

Check warning on line 239 in Deepgram/ClientFactory.cs

GitHub Actions / test (6.0.x)

'Client' is obsolete: 'Please use Deepgram.Clients.Speak.v2.WebSocket instead'

Check warning on line 239 in Deepgram/ClientFactory.cs

GitHub Actions / build

'Client' is obsolete: 'Please use Deepgram.Clients.Speak.v2.WebSocket instead'

Check warning on line 239 in Deepgram/ClientFactory.cs

GitHub Actions / test (7.0.x)

'Client' is obsolete: 'Please use Deepgram.Clients.Speak.v2.WebSocket instead'

Check warning on line 239 in Deepgram/ClientFactory.cs

GitHub Actions / test (8.0.x)

'Client' is obsolete: 'Please use Deepgram.Clients.Speak.v2.WebSocket instead'
case 2:
return new SpeakV2.Client(apiKey, options);
default:
throw new ArgumentException("Invalid version", nameof(version));
}
}
}
1 change: 1 addition & 0 deletions Deepgram/Clients/Analyze/v1/Client.cs
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
using Deepgram.Models.Analyze.v1;
using Deepgram.Models.Authenticate.v1;
using Deepgram.Clients.Interfaces.v1;
using Deepgram.Abstractions.v1;

namespace Deepgram.Clients.Analyze.v1;

16 changes: 8 additions & 8 deletions Deepgram/Clients/Interfaces/v1/ISpeakClient.cs
Original file line number Diff line number Diff line change
@@ -5,14 +5,14 @@
namespace Deepgram.Clients.Interfaces.v1;

/// <summary>
// *********** WARNING ***********
// This class provides the ISpeakClient implementation for the Deepgram API
//
// Deprecated: This class is deprecated. Use the ISpeakRESTClient interface instead.
// This will be removed in a future release.
//
// This package is frozen and no new functionality will be added.
// *********** WARNING ***********
/// *********** WARNING ***********
/// This class provides the ISpeakClient implementation for the Deepgram API
///
/// Deprecated: This class is deprecated. Use the ISpeakRESTClient interface instead.
/// This will be removed in a future release.
///
/// This package is frozen and no new functionality will be added.
/// *********** WARNING ***********
/// </summary>
[Obsolete("Please use ISpeakRESTClient instead", false)]
public interface ISpeakClient : ISpeakRESTClient
Original file line number Diff line number Diff line change
@@ -4,8 +4,13 @@

namespace Deepgram.Clients.Interfaces.v1;

public class IResponseEvent<T>
public class ResponseEvent<T>
{
public T? Response { get; set; }
public T? Response { get; }

public ResponseEvent(T? response)
{
Response = response;
}
}

15 changes: 15 additions & 0 deletions Deepgram/Clients/Interfaces/v2/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Clients.Interfaces.v2;

/// <summary>
/// Headers of interest in the return values from the Deepgram Speak API.
/// </summary>
public static class Constants
{
// WS buffer size
public const int UseArrayLengthForSend = -1;
}

94 changes: 94 additions & 0 deletions Deepgram/Clients/Interfaces/v2/IAnalyzeClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Copyright 2021-2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

using Deepgram.Models.Analyze.v1;

namespace Deepgram.Clients.Interfaces.v2;

/// <summary>
/// Not currently being used
/// </summary>
public interface IAnalyzeClient
{
#region NoneCallBacks
/// <summary>
/// Analyze a file by providing a url
/// </summary>
/// <param name="source">Url to the file that is to be analyzed <see cref="UrlSource"></param>
/// <param name="analyzeSchema">Options for the transcription <see cref="AnalyzeSchema"/></param>
/// <returns><see cref="SyncResponse"/></returns>
public Task<SyncResponse> AnalyzeUrl(UrlSource source, AnalyzeSchema? analyzeSchema, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);

/// <summary>
/// Analyze by providing text
/// </summary>
/// <param name="source">Text that is to be analyzed <see cref="TextSource"></param>
/// <param name="analyzeSchema">Options for the transcription <see cref="AnalyzeSchema"/></param>
/// <returns><see cref="SyncResponse"/></returns>
public Task<SyncResponse> AnalyzeText(TextSource source, AnalyzeSchema? analyzeSchema, CancellationTokenSource? cancellationToken = default, Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);

/// <summary>
/// Analyzes a file using the provided byte array
/// </summary>
/// <param name="source">file is the form of a byte[]</param>
/// <param name="analyzeSchema">Options for the transcription <see cref="AnalyzeSchema"/></param>
/// <returns><see cref="SyncResponse"/></returns>
public Task<SyncResponse> AnalyzeFile(byte[] source, AnalyzeSchema? analyzeSchema, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);

/// <summary>
/// Analyzes a file using the provided stream
/// </summary>
/// <param name="source">file is the form of a stream <see cref="Stream"/></param>
/// <param name="analyzeSchema">Options for the transcription <see cref="AnalyzeSchema"/></param>
/// <returns><see cref="SyncResponse"/></returns>
public Task<SyncResponse> AnalyzeFile(Stream source, AnalyzeSchema? analyzeSchema, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);
#endregion

#region CallBack Methods
/// <summary>
/// Analyzes a file using the provided byte array and providing a CallBack
/// </summary>
/// <param name="source">file is the form of a byte[]</param>
/// <param name="callBack">CallBack url</param>
/// <param name="analyzeSchema">Options for the transcription<see cref="AnalyzeSchema"></param>
/// <returns><see cref="AsyncResponse"/></returns>
public Task<AsyncResponse> AnalyzeFileCallBack(byte[] source, string? callBack, AnalyzeSchema? analyzeSchema,
CancellationTokenSource? cancellationToken = default, Dictionary<string, string>? addons = null,
Dictionary<string, string>? headers = null);

/// <summary>
/// Analyzes a file using the provided stream and providing a CallBack
/// </summary>
/// <param name="source">file is the form of a stream <see cref="Stream"></param>
/// <param name="callBack">CallBack url</param>
/// <param name="analyzeSchema">Options for the transcription<see cref="AnalyzeSchema"></param>
/// <returns><see cref="AsyncResponse"/></returns>
public Task<AsyncResponse> AnalyzeFileCallBack(Stream source, string? callBack, AnalyzeSchema? analyzeSchema,
CancellationTokenSource? cancellationToken = default, Dictionary<string, string>? addons = null,
Dictionary<string, string>? headers = null);

/// <summary>
/// Analyze a file by providing a url and a CallBack
/// </summary>
/// <param name="source">Url to the file that is to be analyzed <see cref="UrlSource"/></param>
/// <param name="callBack">CallBack url</param>
/// <param name="analyzeSchema">Options for the transcription<see cref="AnalyzeSchema"></param>
/// <returns><see cref="AsyncResponse"/></returns>
public Task<AsyncResponse> AnalyzeUrlCallBack(UrlSource source, string? callBack, AnalyzeSchema? analyzeSchema,
CancellationTokenSource? cancellationToken = default, Dictionary<string, string>? addons = null,
Dictionary<string, string>? headers = null);

/// <summary>
/// Analyze by providing text and a CallBack
/// </summary>
/// <param name="source">Text that is to be analyzed <see cref="TextSource"/></param>
/// <param name="callBack">CallBack url</param>
/// <param name="analyzeSchema">Options for the transcription<see cref="AnalyzeSchema"></param>
/// <returns><see cref="AsyncResponse"/></returns>
public Task<AsyncResponse> AnalyzeTextCallBack(TextSource source, string? callBack, AnalyzeSchema? analyzeSchema, CancellationTokenSource? cancellationToken = default, Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);
#endregion
}
79 changes: 79 additions & 0 deletions Deepgram/Clients/Interfaces/v2/IListenRESTClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright 2021-2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

using Deepgram.Models.Listen.v1.REST;

namespace Deepgram.Clients.Interfaces.v2;

/// <summary>
/// Not currently being used
/// </summary>
public interface IListenRESTClient

{
#region NoneCallBacks
/// <summary>
/// Transcribe a file by providing a url
/// </summary>
/// <param name="source">Url to the file that is to be transcribed <see cref="UrlSource"></param>
/// <param name="prerecordedSchema">Options for the transcription <see cref="PreRecordedSchema"/></param>
/// <returns><see cref="SyncResponse"/></returns>
public Task<SyncResponse> TranscribeUrl(UrlSource source, PreRecordedSchema? prerecordedSchema,
CancellationTokenSource? cancellationToken = default, Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);

/// <summary>
/// Transcribes a file using the provided byte array
/// </summary>
/// <param name="source">file is the form of a byte[]</param>
/// <param name="prerecordedSchema">Options for the transcription <see cref="PreRecordedSchema"/></param>
/// <returns><see cref="SyncResponse"/></returns>
public Task<SyncResponse> TranscribeFile(byte[] source, PreRecordedSchema? prerecordedSchema,
CancellationTokenSource? cancellationToken = default, Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);

/// <summary>
/// Transcribes a file using the provided stream
/// </summary>
/// <param name="source">file is the form of a streasm <see cref="Stream"/></param>
/// <param name="prerecordedSchema">Options for the transcription <see cref="PreRecordedSchema"/></param>
/// <returns><see cref="SyncResponse"/></returns>
public Task<SyncResponse> TranscribeFile(Stream source, PreRecordedSchema? prerecordedSchema,
CancellationTokenSource? cancellationToken = default, Dictionary<string, string>? addons = null,
Dictionary<string, string>? headers = null);
#endregion

#region CallBack Methods
/// <summary>
/// Transcribes a file using the provided byte array and providing a CallBack
/// </summary>
/// <param name="source">file is the form of a byte[]</param>
/// <param name="callBack">CallBack url</param>
/// <param name="prerecordedSchema">Options for the transcription<see cref="PreRecordedSchema"></param>
/// <returns><see cref="AsyncResponse"/></returns>
public Task<AsyncResponse> TranscribeFileCallBack(byte[] source, string? callBack, PreRecordedSchema? prerecordedSchema,
CancellationTokenSource? cancellationToken = default, Dictionary<string, string>? addons = null,
Dictionary<string, string>? headers = null);

/// <summary>
/// Transcribes a file using the provided stream and providing a CallBack
/// </summary>
/// <param name="source">file is the form of a stream <see cref="Stream"></param>
/// <param name="callBack">CallBack url</param>
/// <param name="prerecordedSchema">Options for the transcription<see cref="PreRecordedSchema"></param>
/// <returns><see cref="AsyncResponse"/></returns>
public Task<AsyncResponse> TranscribeFileCallBack(Stream source, string? callBack, PreRecordedSchema? prerecordedSchema,
CancellationTokenSource? cancellationToken = default, Dictionary<string, string>? addons = null,
Dictionary<string, string>? headers = null);

/// <summary>
/// Transcribe a file by providing a url and a CallBack
/// </summary>
/// <param name="source">Url to the file that is to be transcribed <see cref="UrlSource"/></param>
/// <param name="callBack">CallBack url</param>
/// <param name="prerecordedSchema">Options for the transcription<see cref="PreRecordedSchema"></param>
/// <returns><see cref="AsyncResponse"/></returns>
public Task<AsyncResponse> TranscribeUrlCallBack(UrlSource source, string? callBack, PreRecordedSchema? prerecordedSchema,
CancellationTokenSource? cancellationToken = default, Dictionary<string, string>? addons = null,
Dictionary<string, string>? headers = null);
#endregion
}
137 changes: 137 additions & 0 deletions Deepgram/Clients/Interfaces/v2/IListenWebSocketClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

using Deepgram.Models.Listen.v2.WebSocket;

namespace Deepgram.Clients.Interfaces.v2;

/// <summary>
/// Implements version 2 of the Live Client.
/// </summary>
public interface IListenWebSocketClient
{
#region Connect and Disconnect
public Task<bool> Connect(LiveSchema options, CancellationTokenSource? cancelToken = null, Dictionary<string, string>? addons = null,
Dictionary<string, string>? headers = null);

public Task<bool> Stop(CancellationTokenSource? cancelToken = null, bool nullByte = false);
#endregion

#region Subscribe Event
/// <summary>
/// Subscribe to an Open event from the Deepgram API
/// </summary>
/// <param name="eventHandler"></param>
/// <returns>True if successful</returns>
public Task<bool> Subscribe(EventHandler<OpenResponse> eventHandler);

/// <summary>
/// Subscribe to a Metadata event from the Deepgram API
/// </summary>
/// <param name="eventHandler"></param>
/// <returns>True if successful</returns>
public Task<bool> Subscribe(EventHandler<MetadataResponse> eventHandler);

/// <summary>
/// Subscribe to a Results event from the Deepgram API
/// </summary>
/// <returns>True if successful</returns>
public Task<bool> Subscribe(EventHandler<ResultResponse> eventHandler);

/// <summary>
/// Subscribe to an UtteranceEnd event from the Deepgram API
/// </summary>
/// <returns>True if successful</returns>
public Task<bool> Subscribe(EventHandler<UtteranceEndResponse> eventHandler);

/// <summary>
/// Subscribe to a SpeechStarted event from the Deepgram API
/// </summary>
/// <returns>True if successful</returns>
public Task<bool> Subscribe(EventHandler<SpeechStartedResponse> eventHandler);

/// <summary>
/// Subscribe to a Close event from the Deepgram API
/// </summary>
/// <returns>True if successful</returns>
public Task<bool> Subscribe(EventHandler<CloseResponse> eventHandler);

/// <summary>
/// Subscribe to an Unhandled event from the Deepgram API
/// </summary>
/// <returns>True if successful</returns>
public Task<bool> Subscribe(EventHandler<UnhandledResponse> eventHandler);

/// <summary>
/// Subscribe to an Error event from the Deepgram API
/// </summary>
/// <returns>True if successful</returns>
public Task<bool> Subscribe(EventHandler<ErrorResponse> eventHandler);
#endregion

#region Send Functions
/// <summary>
/// Sends a KeepAlive message to Deepgram
/// </summary>
public Task SendKeepAlive();

/// <summary>
/// Sends a Finalize message to Deepgram
/// </summary>
public Task SendFinalize();

/// <summary>
/// Sends a Close message to Deepgram
/// </summary>
public Task SendClose(bool nullByte = false);

/// <summary>
/// Sends a binary message over the WebSocket connection.
/// </summary>
/// <param name="data">The data to be sent over the WebSocket.</param>
public void Send(byte[] data, int length = Constants.UseArrayLengthForSend);

/// <summary>
/// This method sends a binary message over the WebSocket connection.
/// </summary>
/// <param name="data"></param>
/// <param name="length">The number of bytes from the data to send. Use `Constants.UseArrayLengthForSend` to send the entire array.</param>
public void SendBinary(byte[] data, int length = Constants.UseArrayLengthForSend);

/// <summary>
/// This method sends a text message over the WebSocket connection.
/// </summary>
/// <param name="data"></param>
/// <param name="length">The number of bytes from the data to send. Use `Constants.UseArrayLengthForSend` to send the entire array.</param>
public void SendMessage(byte[] data, int length = Constants.UseArrayLengthForSend);

/// <summary>
/// This method sends a binary message over the WebSocket connection immediately without queueing.
/// </summary>
/// <param name="data"></param>
/// <param name="length">The number of bytes from the data to send. Use `Constants.UseArrayLengthForSend` to send the entire array.</param>
public Task SendBinaryImmediately(byte[] data, int length = Constants.UseArrayLengthForSend);

/// <summary>
/// This method sends a text message over the WebSocket connection immediately without queueing.
/// </summary>
/// <param name="data"></param>
/// <param name="length">The number of bytes from the data to send. Use `Constants.UseArrayLengthForSend` to send the entire array.</param>
public Task SendMessageImmediately(byte[] data, int length = Constants.UseArrayLengthForSend);
#endregion

#region Helpers
/// <summary>
/// Retrieves the connection state of the WebSocket
/// </summary>
/// <returns>Returns the connection state of the WebSocket</returns>
public WebSocketState State();

/// <summary>
/// Indicates whether the WebSocket is connected
/// </summary>
/// <returns>Returns true if the WebSocket is connected</returns>
public bool IsConnected();
#endregion
}
73 changes: 73 additions & 0 deletions Deepgram/Clients/Interfaces/v2/ILiveClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

using Deepgram.Models.Live.v1;

namespace Deepgram.Clients.Interfaces.v2;

/// <summary>
// *********** WARNING ***********
// This is the ILiveClient interface
//
// Deprecated: This class is deprecated. Use the `IListenWebSocketClient` function instead.
// This will be removed in a future release.
//
// This class is frozen and no new functionality will be added.
// *********** WARNING ***********
/// </summary>
[Obsolete("Please use IListenWebSocketClient instead", false)]
public interface ILiveClient : IListenWebSocketClient
{
#region Subscribe Event
/// <summary>
/// Subscribe to an Open event from the Deepgram API
/// </summary>
/// <param name="eventHandler"></param>
/// <returns>True if successful</returns>
public Task<bool> Subscribe(EventHandler<OpenResponse> eventHandler);

/// <summary>
/// Subscribe to a Metadata event from the Deepgram API
/// </summary>
/// <param name="eventHandler"></param>
/// <returns>True if successful</returns>
public Task<bool> Subscribe(EventHandler<MetadataResponse> eventHandler);

/// <summary>
/// Subscribe to a Results event from the Deepgram API
/// </summary>
/// <returns>True if successful</returns>
public Task<bool> Subscribe(EventHandler<ResultResponse> eventHandler);

/// <summary>
/// Subscribe to an UtteranceEnd event from the Deepgram API
/// </summary>
/// <returns>True if successful</returns>
public Task<bool> Subscribe(EventHandler<UtteranceEndResponse> eventHandler);

/// <summary>
/// Subscribe to a SpeechStarted event from the Deepgram API
/// </summary>
/// <returns>True if successful</returns>
public Task<bool> Subscribe(EventHandler<SpeechStartedResponse> eventHandler);

/// <summary>
/// Subscribe to a Close event from the Deepgram API
/// </summary>
/// <returns>True if successful</returns>
public Task<bool> Subscribe(EventHandler<CloseResponse> eventHandler);

/// <summary>
/// Subscribe to an Unhandled event from the Deepgram API
/// </summary>
/// <returns>True if successful</returns>
public Task<bool> Subscribe(EventHandler<UnhandledResponse> eventHandler);

/// <summary>
/// Subscribe to an Error event from the Deepgram API
/// </summary>
/// <returns>True if successful</returns>
public Task<bool> Subscribe(EventHandler<ErrorResponse> eventHandler);
#endregion
}
251 changes: 251 additions & 0 deletions Deepgram/Clients/Interfaces/v2/IManageClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
// Copyright 2021-2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

using Deepgram.Models.Manage.v1;

namespace Deepgram.Clients.Interfaces.v2;

/// <summary>
/// Not currently being used
/// </summary>
public interface IManageClient
{
#region Projects
/// <summary>
/// Gets projects associated to ApiKey
/// </summary>
/// <returns><see cref="ProjectsResponse"/></returns>
public Task<ProjectsResponse> GetProjects(CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);

/// <summary>
/// Gets project associated with project Id
/// </summary>
/// <param name="projectId">Id of Project</param>
/// <returns><see cref="ProjectResponse"/></returns>
public Task<ProjectResponse> GetProject(string projectId, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);

/// <summary>
/// Update a project associated with the projectID
/// </summary>
/// <param name="projectId">ID of project</param>
/// <param name="updateProjectSchema"><see cref="ProjectSchema"/> for project</param>
/// <returns><see cref="MessageResponse"/></returns>
// USES PATCH
public Task<MessageResponse> UpdateProject(string projectId, ProjectSchema updateProjectSchema, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);

/// <summary>
/// Deletes a project, no response will be returned
/// </summary>
/// <param name="projectId">Id of project</param>
// No response expected
public Task<MessageResponse> DeleteProject(string projectId, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);

/// <summary>
/// leave project associated with the project Id
/// </summary>
/// <param name="projectId">Id of project</param>
/// <returns><see cref="MessageResponse"/></returns>
public Task<MessageResponse> LeaveProject(string projectId, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);

/// <summary>
/// Get all models associated with the project Id
/// </summary>
/// <param name="projectId">Id of project</param>
/// <returns><see cref="ModelsResponse"/></returns>
public Task<ModelsResponse> GetProjectModels(string projectId, ModelSchema? modelSchema = null, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);

/// <summary>
/// Get a specific model associated with the project Id
/// </summary>
/// <param name="projectId">Id of project</param>
/// <param name="modelId">Id of model</param>
/// <returns><see cref="ModelResponse"/></returns>
public Task<ModelResponse> GetProjectModel(string projectId, string modelId, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);
#endregion

#region Models
/// <summary>
/// Gets models available in Deepgram
/// </summary>
/// <returns><see cref="ModelsResponse"/></returns>
public Task<ModelsResponse> GetModels(ModelSchema? modelSchema = null, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);

/// <summary>
/// Gets a specific model within Deepgram
/// </summary>
/// <param name="modelId">ID of model</param>
/// <returns><see cref="ModelResponse"/></returns>
public Task<ModelResponse> GetModel(string modelId, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);
#endregion

#region ProjectKeys
/// <summary>
/// Get the keys associated with the project
/// </summary>
/// <param name="projectId">Id of project</param>
/// <returns><see cref="KeysResponse"/></returns>
public Task<KeysResponse> GetKeys(string projectId, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);

/// <summary>
/// Get details of key associated with the key ID
/// </summary>
/// <param name="projectId">Id of project</param>
/// <param name="keyId">Id of key</param>
/// <returns><see cref="KeyScopeResponse"/></returns>
public Task<KeyScopeResponse> GetKey(string projectId, string keyId, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);

/// <summary>
/// Create a key in the associated project
/// </summary>
/// <param name="projectId">Id of project</param>
/// <param name="keySchema"><see cref="KeySchema"/> for the key to be created</param>
/// <returns><see cref="KeyResponse"/></returns>
public Task<KeyResponse> CreateKey(string projectId, KeySchema keySchema, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);

/// <summary>
/// Remove key from project, No response returned
/// </summary>
/// <param name="projectId">Id of project</param>
/// <param name="keyId">Id of key</param>
// Nothing being returned
public Task<MessageResponse> DeleteKey(string projectId, string keyId, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);
#endregion

#region ProjectInvites
/// <summary>
/// Get any invites that are associated with project
/// </summary>
/// <param name="projectId">Id of project</param>
/// <returns><see cref="InvitesResponse"/></returns>
public Task<InvitesResponse> GetInvites(string projectId, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);

/// <summary>
/// Delete a project invite that has been sent
/// </summary>
/// <param name="projectId">Id of project</param>
/// <param name="email">email of the invite to be removed</param>
//no response expected
public Task<MessageResponse> DeleteInvite(string projectId, string email, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);

/// <summary>
/// Send a invite to the associated project
/// </summary>
/// <param name="projectId">Id of project</param>
/// <param name="inviteSchema"><see cref="InviteSchema"/> for a invite to project</param>
/// <returns><see cref="MessageResponse"/></returns>
public Task<MessageResponse> SendInvite(string projectId, InviteSchema inviteSchema, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);
#endregion

#region Members
/// <summary>
/// Get the members associated with the project
/// </summary>
/// <param name="projectId">Id of project</param>
/// <returns><see cref="MembersResponse"/></returns>
public Task<MembersResponse> GetMembers(string projectId, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);

/// <summary>
/// Get the scopes associated with member
/// </summary>
/// <param name="projectId">Id of project</param>
/// <param name="memberId">Id of member</param>
/// <returns><see cref="MemberScopesResponse"/></returns>
public Task<MemberScopesResponse> GetMemberScopes(string projectId, string memberId, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);

/// <summary>
/// Update the scopes fot the member
/// </summary>
/// <param name="projectId">Id of project</param>
/// <param name="memberId">Id of member</param>
/// <param name="scopeSchema">Updates scope options for member<see cref="MemberScopeSchema"/></param>
/// <returns><see cref="MessageResponse"/></returns>
public Task<MessageResponse> UpdateMemberScope(string projectId, string memberId, MemberScopeSchema scopeSchema,
CancellationTokenSource? cancellationToken = default, Dictionary<string, string>? addons = null,
Dictionary<string, string>? headers = null);

/// <summary>
/// Remove member from project, there is no response
/// </summary>
/// <param name="projectId">Id of project</param>
/// <param name="memberId">Id of member</param>
//No response expected
public Task<MessageResponse> RemoveMember(string projectId, string memberId, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);
#endregion

#region Usage
/// <summary>
/// Get usage request associated with the project
/// </summary>
/// <param name="projectId">Id of project</param>
/// <param name="UsageRequestsSchema">Project usage request options<see cref="UsageRequestsSchema"/> </param>
/// <returns><see cref="UsageRequestsResponse"/></returns>
public Task<UsageRequestsResponse> GetUsageRequests(string projectId, UsageRequestsSchema usageRequestsSchema,
CancellationTokenSource? cancellationToken = default, Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);

/// <summary>
/// Get the details associated with the requestID
/// </summary>
/// <param name="projectId">Id of project</param>
/// <param name="requestId">Id of request</param>
/// <returns><see cref="UsageRequestResponse"/></returns>
public Task<UsageRequestResponse> GetUsageRequest(string projectId, string requestId, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);

/// <summary>
/// Gets a summary of usage
/// </summary>
/// <param name="projectId">Id of project</param>
/// <param name="getUsageSummarySchema">Usage summary options<see cref="UsageSummarySchema"/> </param>
/// <returns><see cref="UsageSummaryResponse"/></returns>
public Task<UsageSummaryResponse> GetUsageSummary(string projectId, UsageSummarySchema summarySchema,
CancellationTokenSource? cancellationToken = default, Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);

/// <summary>
/// Get usage fields
/// </summary>
/// <param name="projectId">Id of project</param>
/// <param name="fieldsSchema">Project usage request field options<see cref="UsageFieldsSchema"/></param>
/// <returns><see cref="UsageFieldsResponse"/></returns>
public Task<UsageFieldsResponse> GetUsageFields(string projectId, UsageFieldsSchema fieldsSchema,
CancellationTokenSource? cancellationToken = default, Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);
#endregion

#region Balances
/// <summary>
/// Gets a list of balances
/// </summary>
/// <param name="projectId">Id of project</param>
/// <returns><see cref="BalancesResponse"/></returns>
public Task<BalancesResponse> GetBalances(string projectId, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);

/// <summary>
/// Get the balance details associated with the balance id
/// </summary>
/// <param name="projectId">Id of project</param>
/// <param name="balanceId">Id of balance</param>
/// <returns><see cref="BalanceResponse"/></returns>
public Task<BalanceResponse> GetBalance(string projectId, string balanceId, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);
#endregion
}
20 changes: 20 additions & 0 deletions Deepgram/Clients/Interfaces/v2/IOnPremClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2021-2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Clients.Interfaces.v2;

/// <summary>
// *********** WARNING ***********
// This class provides the IOnPremClient implementation
//
// Deprecated: This class is deprecated. Use ISelfHostedClient instead.
// This will be removed in a future release.
//
// This package is frozen and no new functionality will be added.
// *********** WARNING ***********
/// </summary>
[Obsolete("Please use ISelfHostedClient instead", false)]
public interface IOnPremClient : ISelfHostedClient
{
}
20 changes: 20 additions & 0 deletions Deepgram/Clients/Interfaces/v2/IPreRecordedClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2021-2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Clients.Interfaces.v2;

/// <summary>
// *********** WARNING ***********
// This is the IPreRecordedClient interface
//
// Deprecated: This class is deprecated. Use the `IListenRESTClient` function instead.
// This will be removed in a future release.
//
// This class is frozen and no new functionality will be added.
// *********** WARNING ***********
/// </summary>
[Obsolete("Please use IListenRESTClient instead", false)]
public interface IPreRecordedClient : IListenRESTClient
{
}
48 changes: 48 additions & 0 deletions Deepgram/Clients/Interfaces/v2/ISelfHostedClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2021-2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

using Deepgram.Models.SelfHosted.v1;

namespace Deepgram.Clients.Interfaces.v2;

/// <summary>
/// Not currently being used
/// </summary>
public interface ISelfHostedClient
{
/// <summary>
/// get a list of credentials associated with project
/// </summary>
/// <param name="projectId">Id of project</param>
/// <returns><see cref="CredentialsResponse"/></returns>
public Task<CredentialsResponse> ListCredentials(string projectId, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);

/// <summary>
/// Get credentials for the project that is associated with credential ID
/// </summary>
/// <param name="projectId">Id of project</param>
/// <param name="credentialsId">Id of credentials</param>
/// <returns><see cref="CredentialResponse"/></returns>
public Task<CredentialResponse> GetCredentials(string projectId, string credentialsId, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);

/// <summary>
/// Remove credentials in the project associated with the credentials ID
/// </summary>
/// <param name="projectId">Id of project</param>
/// <param name="credentialsId">Id of credentials</param>
/// <returns><see cref="MessageResponse"/></returns>
public Task<MessageResponse> DeleteCredentials(string projectId, string credentialsId, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);

/// <summary>
/// Create credentials for the associated projects
/// </summary>
/// <param name="projectId">Id of project</param>
/// <param name="createOnPremCredentialsSchema"><see cref="CredentialsSchema"/> for credentials to be created</param>
/// <returns><see cref="CredentialResponse"/></returns>
public Task<CredentialResponse> CreateCredentials(string projectId, CredentialsSchema credentialsSchema,
CancellationTokenSource? cancellationToken = default, Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);
}
20 changes: 20 additions & 0 deletions Deepgram/Clients/Interfaces/v2/ISpeakClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Clients.Interfaces.v2;

/// <summary>
/// *********** WARNING ***********
/// This class provides the ISpeakClient implementation for the Deepgram API
///
/// Deprecated: This class is deprecated. Use the ISpeakRESTClient interface instead.
/// This will be removed in a future release.
///
/// This package is frozen and no new functionality will be added.
/// *********** WARNING ***********
/// </summary>
[Obsolete("Please use ISpeakRESTClient instead", false)]
public interface ISpeakClient : ISpeakRESTClient
{
}
39 changes: 39 additions & 0 deletions Deepgram/Clients/Interfaces/v2/ISpeakRESTClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

using Deepgram.Models.Speak.v1.REST;

namespace Deepgram.Clients.Interfaces.v2;

/// <summary>
/// Not currently being used
/// </summary>
public interface ISpeakRESTClient
{
#region NoneCallBacks
/// <summary>
/// Speaks a file using the provided stream
/// </summary>
/// <param name="source">file is the form of a stream <see cref="Stream"/></param>
/// <param name="speakSchema">Options for the transcription <see cref="SpeakSchema"/></param>
/// <returns><see cref="SyncResponse"/></returns>
public Task<SyncResponse> ToStream(TextSource source, SpeakSchema? speakSchema, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);

public Task<SyncResponse> ToFile(TextSource source, string filename, SpeakSchema? speakSchema, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);
#endregion

#region CallBack Methods
/// <summary>
/// Speaks a file using the provided byte array and providing a CallBack
/// </summary>
/// <param name="source">file is the form of a byte[]</param>
/// <param name="callBack">CallBack url</param>
/// <param name="speakSchema">Options for the transcription<see cref="SpeakSchema"></param>
/// <returns><see cref="AsyncResponse"/></returns>
public Task<AsyncResponse> StreamCallBack(TextSource source, string? callBack, SpeakSchema? speakSchema, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);
#endregion
}
159 changes: 159 additions & 0 deletions Deepgram/Clients/Interfaces/v2/ISpeakWebSocketClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

using Deepgram.Models.Speak.v2.WebSocket;

namespace Deepgram.Clients.Interfaces.v2;

/// <summary>
/// Implements version 2 of the Live Client.
/// </summary>
public interface ISpeakWebSocketClient
{
#region Connect and Disconnect
public Task<bool> Connect(SpeakSchema options, CancellationTokenSource? cancelToken = null, Dictionary<string, string>? addons = null,
Dictionary<string, string>? headers = null);

public Task<bool> Stop(CancellationTokenSource? cancelToken = null, bool nullByte = false);
#endregion

#region Subscribe Event
/// <summary>
/// Subscribe to an Open event from the Deepgram API
/// </summary>
/// <param name="eventHandler"></param>
/// <returns>True if successful</returns>
public Task<bool> Subscribe(EventHandler<OpenResponse> eventHandler);

/// <summary>
/// Subscribe to a Metadata event from the Deepgram API
/// </summary>
/// <param name="eventHandler"></param>
/// <returns>True if successful</returns>
public Task<bool> Subscribe(EventHandler<MetadataResponse> eventHandler);

/// <summary>
/// Subscribe to a Flushed event from the Deepgram API
/// </summary>
/// <returns>True if successful</returns>
public Task<bool> Subscribe(EventHandler<FlushedResponse> eventHandler);

/// <summary>
/// Subscribe to a Cleared event from the Deepgram API
/// </summary>
/// <returns>True if successful</returns>
public Task<bool> Subscribe(EventHandler<ClearedResponse> eventHandler);

/// <summary>
/// Subscribe to a Audio buffer/event from the Deepgram API
/// </summary>
/// <returns>True if successful</returns>
public Task<bool> Subscribe(EventHandler<AudioResponse> eventHandler);

/// <summary>
/// Subscribe to a Close event from the Deepgram API
/// </summary>
/// <returns>True if successful</returns>
public Task<bool> Subscribe(EventHandler<CloseResponse> eventHandler);

/// <summary>
/// Subscribe to an Warning event from the Deepgram API
/// </summary>
/// <returns>True if successful</returns>
public Task<bool> Subscribe(EventHandler<WarningResponse> eventHandler);


/// <summary>
/// Subscribe to an Error event from the Deepgram API
/// </summary>
/// <returns>True if successful</returns>
public Task<bool> Subscribe(EventHandler<ErrorResponse> eventHandler);

/// <summary>
/// Subscribe to an Unhandled event from the Deepgram API
/// </summary>
/// <returns>True if successful</returns>
public Task<bool> Subscribe(EventHandler<UnhandledResponse> eventHandler);
#endregion

#region Send Functions
/// <summary>
/// Sends text data over the WebSocket connection.
/// </summary>
/// <param name="data"></param>
public void SpeakWithText(string data);

///// <summary>
///// This method Flushes the text buffer on Deepgram to be converted to audio
///// </summary>
public void Flush();

///// <summary>
///// This method Resets the text buffer on Deepgram to be converted to audio
///// </summary>
public void Clear();

///// <summary>
///// This method tells Deepgram to initiate the close server-side.
///// </summary>
public void Close(bool nullByte = false);

///// <summary>
///// This method sends a binary message over the WebSocket connection.
///// </summary>
///// <param name="data"></param>
//public void SpeakWithStream(byte[] data);

/// <summary>
/// Sends a Close message to Deepgram
/// </summary>
public Task SendClose(bool nullByte = false);

/// <summary>
/// Sends a binary message over the WebSocket connection.
/// </summary>
/// <param name="data"></param>
/// <param name="length">The number of bytes from the data to send. Use `Constants.UseArrayLengthForSend` to send the entire array.</param>
public void Send(byte[] data, int length = Constants.UseArrayLengthForSend);

///// <summary>
///// This method sends a binary message over the WebSocket connection.
///// </summary>
///// <param name="data"></param>
//public void SendBinary(byte[] data, int length = Constants.UseArrayLengthForSend);

/// <summary>
/// This method sends a text message over the WebSocket connection.
/// </summary>
/// <param name="data"></param>
/// <param name="length">The number of bytes from the data to send. Use `Constants.UseArrayLengthForSend` to send the entire array.</param>
public void SendMessage(byte[] data, int length = Constants.UseArrayLengthForSend);

///// <summary>
///// This method sends a binary message over the WebSocket connection immediately without queueing.
///// </summary>
//public Task SendBinaryImmediately(byte[] data, int length = Constants.UseArrayLengthForSend);

/// <summary>
/// This method sends a text message over the WebSocket connection immediately without queueing.
/// </summary>
/// <param name="data"></param>
/// <param name="length">The number of bytes from the data to send. Use `Constants.UseArrayLengthForSend` to send the entire array.</param>
public Task SendMessageImmediately(byte[] data, int length = Constants.UseArrayLengthForSend);
#endregion

#region Helpers
/// <summary>
/// Retrieves the connection state of the WebSocket
/// </summary>
/// <returns>Returns the connection state of the WebSocket</returns>
public WebSocketState State();

/// <summary>
/// Indicates whether the WebSocket is connected
/// </summary>
/// <returns>Returns true if the WebSocket is connected</returns>
public bool IsConnected();
#endregion
}
16 changes: 16 additions & 0 deletions Deepgram/Clients/Interfaces/v2/ResponseEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2021-2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Clients.Interfaces.v2;

public class ResponseEvent<T>
{
public T? Response { get; }

public ResponseEvent(T? response)
{
Response = response;
}
}

1 change: 1 addition & 0 deletions Deepgram/Clients/Listen/v1/REST/Client.cs
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
using Deepgram.Models.Authenticate.v1;
using Deepgram.Models.Listen.v1.REST;
using Deepgram.Clients.Interfaces.v1;
using Deepgram.Abstractions.v1;

namespace Deepgram.Clients.Listen.v1.REST;

10 changes: 9 additions & 1 deletion Deepgram/Clients/Listen/v1/WebSocket/Client.cs
Original file line number Diff line number Diff line change
@@ -11,8 +11,16 @@
namespace Deepgram.Clients.Listen.v1.WebSocket;

/// <summary>
/// Implements version 1 of the Live Client.
// *********** WARNING ***********
// Implements version 1 of the Listen WebSocket Client
//
// Deprecated: This class is deprecated. Use the `v2` of the client instead.
// This will be removed in a future release.
//
// This class is frozen and no new functionality will be added.
// *********** WARNING ***********
/// </summary>
[Obsolete("Please use Deepgram.Clients.Listen.v2.WebSocket instead", false)]
public class Client : IDisposable, IListenWebSocketClient
{
#region Fields
658 changes: 658 additions & 0 deletions Deepgram/Clients/Listen/v2/WebSocket/Client.cs

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions Deepgram/Clients/Listen/v2/WebSocket/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Clients.Listen.v2.WebSocket;

/// <summary>
/// Headers of interest in the return values from the Deepgram Speak API.
/// </summary>
public static class Constants
{
// Default flush period
public const int DefaultFlushPeriodInMs = 500;
}

11 changes: 11 additions & 0 deletions Deepgram/Clients/Listen/v2/WebSocket/ResponseEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2021-2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Clients.Listen.v2.WebSocket;

public class ResponseEvent<T>(T? response) : EventArgs
{
public T? Response { get; set; } = response;
}

12 changes: 12 additions & 0 deletions Deepgram/Clients/Listen/v2/WebSocket/UriSegments.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2021-2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Clients.Listen.v2.WebSocket;

public static class UriSegments
{
//using constants instead of inline value(magic strings) make consistence
//across SDK And Test Projects Simpler and Easier to change
public const string LISTEN = "listen";
}
1 change: 1 addition & 0 deletions Deepgram/Clients/Manage/v1/Client.cs
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
using Deepgram.Models.Authenticate.v1;
using Deepgram.Models.Manage.v1;
using Deepgram.Clients.Interfaces.v1;
using Deepgram.Abstractions.v1;

namespace Deepgram.Clients.Manage.v1;

1 change: 1 addition & 0 deletions Deepgram/Clients/SelfHosted/v1/Client.cs
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
using Deepgram.Models.Authenticate.v1;
using Deepgram.Models.SelfHosted.v1;
using Deepgram.Clients.Interfaces.v1;
using Deepgram.Abstractions.v1;

namespace Deepgram.Clients.SelfHosted.v1;

1 change: 1 addition & 0 deletions Deepgram/Clients/Speak/v1/REST/Client.cs
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
using Deepgram.Models.Speak.v1.REST;
using Deepgram.Models.Authenticate.v1;
using Deepgram.Clients.Interfaces.v1;
using Deepgram.Abstractions.v1;

namespace Deepgram.Clients.Speak.v1.REST;

10 changes: 9 additions & 1 deletion Deepgram/Clients/Speak/v1/WebSocket/Client.cs
Original file line number Diff line number Diff line change
@@ -11,8 +11,16 @@
namespace Deepgram.Clients.Speak.v1.WebSocket;

/// <summary>
/// Implements version 1 of the Live Client.
// *********** WARNING ***********
// Implements version 1 of the Speak WebSocket Client
//
// Deprecated: This class is deprecated. Use the `v2` of the client instead.
// This will be removed in a future release.
//
// This class is frozen and no new functionality will be added.
// *********** WARNING ***********
/// </summary>
[Obsolete("Please use Deepgram.Clients.Speak.v2.WebSocket instead", false)]
public class Client : IDisposable, ISpeakWebSocketClient
{
#region Fields
9 changes: 7 additions & 2 deletions Deepgram/Clients/Speak/v1/WebSocket/ResponseEvent.cs
Original file line number Diff line number Diff line change
@@ -4,8 +4,13 @@

namespace Deepgram.Clients.Speak.v1.WebSocket;

public class ResponseEvent<T>(T? response) : EventArgs
public class ResponseEvent<T> : EventArgs
{
public T? Response { get; set; } = response;
public T? Response { get; }

public ResponseEvent(T? response)
{
Response = response;
}
}

711 changes: 711 additions & 0 deletions Deepgram/Clients/Speak/v2/WebSocket/Client.cs

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions Deepgram/Clients/Speak/v2/WebSocket/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Clients.Speak.v2.WebSocket;

/// <summary>
/// Headers of interest in the return values from the Deepgram Speak API.
/// </summary>
public static class Constants
{
// WS buffer size
public const int BufferSize = 1024 * 16;
public const int UseArrayLengthForSend = -1;

// Default timeout for connect/disconnect
public const int DefaultConnectTimeout = 5000;
public const int DefaultDisconnectTimeout = 5000;

public const int DefaultFlushPeriodInMs = 500;

// user message types
public const string Speak = "Speak";
public const string Flush = "Flush";
public const string Clear = "Clear";
public const string Close = "Close";
}

16 changes: 16 additions & 0 deletions Deepgram/Clients/Speak/v2/WebSocket/ResponseEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Clients.Speak.v2.WebSocket;

public class ResponseEvent<T> : EventArgs
{
public T? Response { get; }

public ResponseEvent(T? response)
{
Response = response;
}
}

12 changes: 12 additions & 0 deletions Deepgram/Clients/Speak/v2/WebSocket/UriSegments.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Clients.Speak.v2.WebSocket;

public static class UriSegments
{
//using constants instead of inline value(magic strings) make consistence
//across SDK And Test Projects Simpler and Easier to change
public const string SPEAK = "speak";
}
2 changes: 0 additions & 2 deletions Deepgram/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

global using System.Collections.Concurrent;
global using System.Net.Http.Headers;
global using System.Net.WebSockets;
global using System.Reflection;
@@ -12,7 +11,6 @@
global using System.Text.RegularExpressions;
global using System.Threading.Channels;
global using System.Web;
global using Deepgram.Abstractions;
global using Deepgram.Constants;
global using Deepgram.Logger;
global using Deepgram.Utilities;
2 changes: 1 addition & 1 deletion Deepgram/ListenWebSocketClient.cs
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

using Deepgram.Clients.Listen.v1.WebSocket;
using Deepgram.Clients.Listen.v2.WebSocket;
using Deepgram.Models.Authenticate.v1;

namespace Deepgram;
37 changes: 37 additions & 0 deletions Deepgram/Models/Common/v2/WebSocket/CloseResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Models.Common.v2.WebSocket;

public record CloseResponse
{
/// <summary>
/// Close event type.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("type")]
[JsonConverter(typeof(JsonStringEnumConverter))]
public WebSocketType? Type { get; set; } = WebSocketType.Close;

/// <summary>
/// Copy method to copy the object
/// </summary>
public void Copy(CloseResponse other)
{
if (other is null)
{
return;
}

Type = other.Type;
}

/// <summary>
/// Override ToString method to serialize the object
/// </summary>
public override string ToString()
{
return Regex.Unescape(JsonSerializer.Serialize(this, JsonSerializeOptions.DefaultOptions));
}
}
61 changes: 61 additions & 0 deletions Deepgram/Models/Common/v2/WebSocket/ErrorResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Models.Common.v2.WebSocket;

public record ErrorResponse
{
/// <summary>
/// Error Description
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("description")]
public string? Description { get; set; } = "";

/// <summary>
/// Error Message
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("message")]
public string? Message { get; set; } = "";

/// <summary>
/// Error Variant
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("variant")]
public string? Variant { get; set; } = "";

/// <summary>
/// Error event type.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("type")]
[JsonConverter(typeof(JsonStringEnumConverter))]
public WebSocketType? Type { get; set; } = WebSocketType.Error;

/// <summary>
/// Copy method to copy the object
/// </summary>
public void Copy(ErrorResponse other)
{
if (other is null)
{
return;
}

Description = other.Description;
Message = other.Message;
Variant = other.Variant;
Type = other.Type;
}

/// <summary>
/// Override ToString method to serialize the object
/// </summary>
public override string ToString()
{
return Regex.Unescape(JsonSerializer.Serialize(this, JsonSerializeOptions.DefaultOptions));
}
}
37 changes: 37 additions & 0 deletions Deepgram/Models/Common/v2/WebSocket/OpenResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Models.Common.v2.WebSocket;

public record OpenResponse
{
/// <summary>
/// Open event type.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("type")]
[JsonConverter(typeof(JsonStringEnumConverter))]
public WebSocketType? Type { get; set; } = WebSocketType.Open;

/// <summary>
/// Copy method to copy the object
/// </summary>
public void Copy(OpenResponse other)
{
if (other is null)
{
return;
}

Type = other.Type;
}

/// <summary>
/// Override ToString method to serialize the object
/// </summary>
public override string ToString()
{
return Regex.Unescape(JsonSerializer.Serialize(this, JsonSerializeOptions.DefaultOptions));
}
}
45 changes: 45 additions & 0 deletions Deepgram/Models/Common/v2/WebSocket/UnhandledResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Models.Common.v2.WebSocket;

public record UnhandledResponse
{
/// <summary>
/// Raw JSON
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("raw")]
public string? Raw { get; set; } = "";

/// <summary>
/// Unhandled event type.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("type")]
[JsonConverter(typeof(JsonStringEnumConverter))]
public WebSocketType? Type { get; set; } = WebSocketType.Unhandled;

/// <summary>
/// Copy method to copy the object
/// </summary>
public void Copy(UnhandledResponse other)
{
if (other == null)
{
return;
}

Raw = other.Raw;
Type = other.Type;
}

/// <summary>
/// Override ToString method to serialize the object
/// </summary>
public override string ToString()
{
return Regex.Unescape(JsonSerializer.Serialize(this, JsonSerializeOptions.DefaultOptions));
}
}
13 changes: 13 additions & 0 deletions Deepgram/Models/Common/v2/WebSocket/WebSocketType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2021-2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Models.Common.v2.WebSocket;

public enum WebSocketType
{
Open,
Close,
Unhandled,
Error,
}
43 changes: 43 additions & 0 deletions Deepgram/Models/Listen/v2/WebSocket/Alternative.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2021-2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Models.Listen.v2.WebSocket;

public record Alternative
{
/// <summary>
/// Single-string transcript containing what the model hears in this channel of audio.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("transcript")]
public string? Transcript { get; set; }
/// <summary>
/// Value between 0 and 1 indicating the model's relative confidence in this transcript.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("confidence")]
public double? Confidence { get; set; }

/// <summary>
/// ReadOnly List of <see cref="Word"/> objects.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("words")]
public IReadOnlyList<Word>? Words { get; set; }

/// <summary>
/// ReadOnlyList of Languages Detected
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("languages")]
public IReadOnlyList<string>? Languages { get; set; }

/// <summary>
/// Override ToString method to serialize the object
/// </summary>
public override string ToString()
{
return Regex.Unescape(JsonSerializer.Serialize(this, JsonSerializeOptions.DefaultOptions));
}
}
30 changes: 30 additions & 0 deletions Deepgram/Models/Listen/v2/WebSocket/Average.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2021-2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Models.Listen.v2.WebSocket;

public record Average
{
/// <summary>
/// Sentiment: Positive, Negative, or Neutral.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("sentiment")]
public string? Sentiment { get; set; }

/// <summary>
/// Sentiment score.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("sentiment_score")]
public double? SentimentScore { get; set; }

/// <summary>
/// Override ToString method to serialize the object
/// </summary>
public override string ToString()
{
return Regex.Unescape(JsonSerializer.Serialize(this, JsonSerializeOptions.DefaultOptions));
}
}
30 changes: 30 additions & 0 deletions Deepgram/Models/Listen/v2/WebSocket/Channel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2021-2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Models.Listen.v2.WebSocket;

public record Channel
{
/// <summary>
/// ReadOnlyList of <see cref="Alternative"/> objects.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("alternatives")]
public IReadOnlyList<Alternative>? Alternatives { get; set; }

/// <summary>
/// ReadOnlyList of Search objects.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("search")]
public IReadOnlyList<Search>? Search { get; set; }

/// <summary>
/// Override ToString method to serialize the object
/// </summary>
public override string ToString()
{
return Regex.Unescape(JsonSerializer.Serialize(this, JsonSerializeOptions.DefaultOptions));
}
}
11 changes: 11 additions & 0 deletions Deepgram/Models/Listen/v2/WebSocket/CloseResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Models.Listen.v2.WebSocket;

using Common = Deepgram.Models.Common.v2.WebSocket;

public record CloseResponse : Common.CloseResponse
{
}
11 changes: 11 additions & 0 deletions Deepgram/Models/Listen/v2/WebSocket/ErrorResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Models.Listen.v2.WebSocket;

using Common = Deepgram.Models.Common.v2.WebSocket;

public record ErrorResponse : Common.ErrorResponse
{
}
45 changes: 45 additions & 0 deletions Deepgram/Models/Listen/v2/WebSocket/Hit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2021-2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Models.Listen.v2.WebSocket;

public record Hit
{
/// <summary>
/// Value between 0 and 1 that indicates the model's relative confidence in this hit.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("confidence")]
public double? Confidence { get; set; }


/// <summary>
/// Offset in seconds from the start of the audio to where the hit ends.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("end")]
public decimal? End { get; set; }

/// <summary>
/// Transcript that corresponds to the time between start and end.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("snippet")]
public string? Snippet { get; set; }

/// <summary>
/// Offset in seconds from the start of the audio to where the hit occurs.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("start")]
public decimal? Start { get; set; }

/// <summary>
/// Override ToString method to serialize the object
/// </summary>
public override string ToString()
{
return Regex.Unescape(JsonSerializer.Serialize(this, JsonSerializeOptions.DefaultOptions));
}
}
19 changes: 19 additions & 0 deletions Deepgram/Models/Listen/v2/WebSocket/ListenType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2021-2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Models.Listen.v2.WebSocket;

using Deepgram.Models.Common.v2.WebSocket;

public enum ListenType
{
Open = WebSocketType.Open,
Close = WebSocketType.Close,
Unhandled = WebSocketType.Unhandled,
Error = WebSocketType.Error,
Metadata,
Results,
UtteranceEnd,
SpeechStarted,
}
262 changes: 262 additions & 0 deletions Deepgram/Models/Listen/v2/WebSocket/LiveSchema.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
// Copyright 2021-2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Models.Listen.v2.WebSocket;

public class LiveSchema
{

/// <summary>
/// Number of transcripts to return per request
/// <see href="https://developers.deepgram.com/reference/pre-recorded"/>
/// Default is 1
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("alternatives")]
public int? Alternatives { get; set; }

/// <summary>
/// CallBack allows you to have your submitted audio processed asynchronously.
/// <see href="https://developers.deepgram.com/docs/callback">
/// default is null
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("callback")]
public string? CallBack { get; set; }

/// <summary>
/// Enables callback method
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("callback_method")]
public bool? CallbackMethod { get; set; }

/// <summary>
/// Channels allows you to specify the number of independent audio channels your submitted audio contains.
/// Used when the Encoding feature is also being used to submit streaming raw audio
/// <see href="https://developers.deepgram.com/docs/channels">
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("channels")]
public int? Channels { get; set; }

/// <summary>
/// Diarize recognizes speaker changes and assigns a speaker to each word in the transcript.
/// <see href="https://developers.deepgram.com/docs/diarization">
/// default is false
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("diarize")]
public bool? Diarize { get; set; }

// <summary>
/// <see href="https://developers.deepgram.com/docs/diarization">
/// default is null, only applies if Diarize is set to true
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("diarize_version")]
public string? DiarizeVersion { get; set; }

/// <summary>
/// Dictation is a feature of Deepgram’s Speech-to-Text API that converts spoken dictation commands into their corresponding punctuation marks.
/// <see href="https://developers.deepgram.com/docs/dictation">
/// default is false
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("dictation")]
public bool? Dictation { get; set; }

/// <summary>
/// Encoding allows you to specify the expected encoding of your submitted audio.
/// <see href="https://developers.deepgram.com/docs/encoding">
/// supported encodings <see cref="AudioEncoding"/>
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("encoding")]
public string? Encoding { get; set; }

/// <summary>
/// Endpointing returns transcripts when pauses in speech are detected.
/// <see href="https://developers.deepgram.com/docs/endpointing">
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("endpointing")]
public string? EndPointing { get; set; }

/// <summary>
/// Deepgram’s Extra Metadata feature allows you to attach arbitrary key-value pairs to your API requests that are attached to the API response for usage in downstream processing.
/// Extra metadata is limited to 2048 characters per key-value pair.
/// <see href="https://developers.deepgram.com/docs/extra-metadata"/>
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("extra")]
public Dictionary<string, string>? Extra { get; set; }

/// <summary>
/// Whether to include words like "uh" and "um" in transcription output.
///<see href="https://developers.deepgram.com/reference/pre-recorded"/>
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("filler_words")]
public bool? FillerWords { get; set; }

/// <summary>
/// Interim Results provides preliminary results for streaming audio to solve the need for immediate results combined with high levels of accuracy.
/// <see href="https://developers.deepgram.com/docs/interim-results">
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("interim_results")]
public bool? InterimResults { get; set; }

/// <summary>
/// Keywords can boost or suppress specialized terminology.
/// <see href="https://developers.deepgram.com/docs/keywords">
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("keywords")]
public List<string>? Keywords { get; set; }

/// <summary>
/// Primary spoken language of submitted audio
/// <see href="https://developers.deepgram.com/docs/language">
/// default value is 'en'
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("language")]
public string? Language { get; set; }

/// <summary>
/// AI model used to process submitted audio
/// <see href="https://developers.deepgram.com/docs/model">
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("model")]
public string? Model { get; set; }

/// <summary>
/// Multichannel transcribes each channel in submitted audio independently.
/// <see href="https://developers.deepgram.com/docs/multichannel">
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("multichannel")]
public bool? MultiChannel { get; set; }

/// <summary>
/// Enables No Delay
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("no_delay")]
public bool? NoDelay { get; set; }

/// <summary>
/// Numerals converts numbers from written format to numerical format.
/// <see href="https://developers.deepgram.com/docs/numerals">
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("numerals")]
public bool? Numerals { get; set; }

/// <summary>
/// Profanity Filter looks for recognized profanity and converts it to the nearest recognized
/// non-profane word or removes it from the transcript completely.
/// <see href="https://developers.deepgram.com/docs/profanity-filter">
/// for use with base model tier only
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("profanity_filter")]
public bool? ProfanityFilter { get; set; }

/// <summary>
/// Adds punctuation and capitalization to transcript
/// <see href="https://developers.deepgram.com/docs/punctuation">
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("punctuate")]
public bool? Punctuate { get; set; }

/// <summary>
/// Indicates whether to redact sensitive information, replacing redacted content with asterisks (*). Can send multiple instances in query string (for example, redact=pci&redact=numbers).
/// <see href="https://developers.deepgram.com/docs/redaction">
/// default is List<string>("false")
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("redact")]
public List<string>? Redact { get; set; }

/// <summary>
/// Find and Replace searches for terms or phrases in submitted audio and replaces them.
/// <see href="https://developers.deepgram.com/docs/find-and-replace">
/// default is null
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("replace")]
public List<string>? Replace { get; set; }

/// <summary>
/// Sample Rate allows you to specify the sample rate of your submitted audio.
/// <see href="https://developers.deepgram.com/docs/sample-rate">
/// only applies when Encoding has a value
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("sample_rate")]
public int? SampleRate { get; set; }

/// <summary>
/// Search searches for terms or phrases in submitted audio.
/// <see href="https://developers.deepgram.com/docs/search">
/// default is null
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("search")]
public List<string>? Search { get; set; }

/// <summary>
/// Smart Format formats transcripts to improve readability.
/// <see href="https://developers.deepgram.com/docs/smart-format">
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("smart_format")]
public bool? SmartFormat { get; set; }

/// <summary>
/// Tagging allows you to label your requests with one or more tags in a list,for the purpose of identification during usage reporting.
/// <see href="https://developers.deepgram.com/docs/tagging">
/// Default is a null
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("tag")]
public List<string>? Tag { get; set; }

/// <summary>
/// Indicates how long Deepgram will wait to send a {"type": "UtteranceEnd"} message after a word has been transcribed
/// <see href="https://developers.deepgram.com/docs/understanding-end-of-speech-detection-while-streaming"/>
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("utterance_end_ms")]
public string? UtteranceEnd { get; set; }

/// <summary>
/// Enables voice activity detection (VAD) events
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("vad_events")]
public bool? VadEvents { get; set; }

/// <summary>
/// Version of the model to use.
/// <see href="https://developers.deepgram.com/docs/version">
/// default value is "latest"
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("version")]
public string? Version { get; set; }

/// <summary>
/// Override ToString method to serialize the object
/// </summary>
public override string ToString()
{
return Regex.Unescape(JsonSerializer.Serialize(this, JsonSerializeOptions.DefaultOptions));
}
}
46 changes: 46 additions & 0 deletions Deepgram/Models/Listen/v2/WebSocket/Metadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2021-2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Models.Listen.v2.WebSocket;

public record MetaData
{
/// <summary>
/// The request ID is a unique identifier for the request. It is useful for troubleshooting and support.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("request_id")]
public string? RequestId { get; set; }

/// <summary>
/// Model UUID
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("model_uuid")]
public string? ModelUUID { get; set; }

/// <summary>
/// IReadonlyDictionary of <see cref="ModelInfo"/>
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("model_info")]
public ModelInfo? ModelInfo { get; set; }

/// <summary>
/// Deepgram’s Extra Metadata feature allows you to attach arbitrary key-value pairs to your API requests that are attached to the API response for usage in downstream processing.
/// Extra metadata is limited to 2048 characters per key-value pair.
/// <see href="https://developers.deepgram.com/docs/extra-metadata"/>
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("extra")]
public Dictionary<string, string>? Extra { get; set; }

/// <summary>
/// Override ToString method to serialize the object
/// </summary>
public override string ToString()
{
return Regex.Unescape(JsonSerializer.Serialize(this, JsonSerializeOptions.DefaultOptions));
}
}
89 changes: 89 additions & 0 deletions Deepgram/Models/Listen/v2/WebSocket/MetadataResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright 2021-2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Models.Listen.v2.WebSocket;

public record MetadataResponse
{
/// <summary>
/// Channel count
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("channels")]
public int? Channels { get; set; }

/// <summary>
/// Created date/time
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("created")]
public DateTime? Created { get; set; }

/// <summary>
/// Duration of the audio
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("duration")]
public double? Duration { get; set; }

/// <summary>
/// Model Information
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("model_info")]
public IReadOnlyDictionary<string, ModelInfo>? ModelInfo { get; set; }

/// <summary>
/// Models used containing UUIDs
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("models")]
public IReadOnlyList<string>? Models { get; set; }

/// <summary>
/// Request ID is a unique identifier for the request. It is useful for troubleshooting and support.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("request_id")]
public string? RequestId { get; set; }

/// <summary>
/// Sha256 information
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("sha256")]
public string? Sha256 { get; set; }

/// <summary>
/// (Obsolete?) his field is only present if the request was made with a transaction key.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("transaction_key")]
public string? TransactionKey { get; set; }

/// <summary>
/// Metadata event type.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("type")]
[JsonConverter(typeof(JsonStringEnumConverter))]
public ListenType? Type { get; set; } = ListenType.Metadata;

/// <summary>
/// Deepgram’s Extra Metadata feature allows you to attach arbitrary key-value pairs to your API requests that are attached to the API response for usage in downstream processing.
/// Extra metadata is limited to 2048 characters per key-value pair.
/// <see href="https://developers.deepgram.com/docs/extra-metadata"/>
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("extra")]
public Dictionary<string, string>? Extra { get; set; }

/// <summary>
/// Override ToString method to serialize the object
/// </summary>
public override string ToString()
{
return Regex.Unescape(JsonSerializer.Serialize(this, JsonSerializeOptions.DefaultOptions));
}
}
37 changes: 37 additions & 0 deletions Deepgram/Models/Listen/v2/WebSocket/ModelInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2021-2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Models.Listen.v2.WebSocket;

public record ModelInfo
{
/// <summary>
/// Architecture of the model
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("arch")]
public string? Arch { get; set; }

/// <summary>
/// Name of the model
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("name")]
public string? Name { get; set; }

/// <summary>
/// Version of the model
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("version")]
public string? Version { get; set; }

/// <summary>
/// Override ToString method to serialize the object
/// </summary>
public override string ToString()
{
return Regex.Unescape(JsonSerializer.Serialize(this, JsonSerializeOptions.DefaultOptions));
}
}
11 changes: 11 additions & 0 deletions Deepgram/Models/Listen/v2/WebSocket/OpenResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Models.Listen.v2.WebSocket;

using Common = Deepgram.Models.Common.v2.WebSocket;

public record OpenResponse : Common.OpenResponse
{
}
Loading

0 comments on commit ba0f717

Please sign in to comment.