Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Client Interfaces and Factory Methods #274

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions Deepgram.Dev.sln
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,26 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "http", "http", "{5DFC6330-8
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Streaming", "examples\streaming\http\Streaming.csproj", "{61B42F6B-521C-4A07-B592-54975F4AE2E6}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "factory_example", "factory_example", "{ACF6E046-747E-440D-BF10-B1E308BF8D60}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "factory_example", "factory_example", "{FCFC3960-C92C-43E4-B864-06B9DF621818}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "factory_example", "factory_example", "{6DFDB911-5172-44F0-A3F1-98C301D7B26F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "factory_example", "factory_example", "{C5428CBF-4741-46E6-A721-AF00716CBAA8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "factory_example", "factory_example", "{2B3AF9D0-879A-4B8A-A6EC-0C95F36A1DC5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Factory", "examples\analyze\factory_example\Factory.csproj", "{8B6FC081-6103-49EB-96A3-84FED3F5181D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Factory", "examples\manage\factory_example\Factory.csproj", "{92C795B8-9002-447E-BFE5-B227D1BA3B22}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Factory", "examples\prerecorded\factory_example\Factory.csproj", "{CB254D55-5C90-4EAF-8EE7-5C9C284317E7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Factory", "examples\speak\file\factory_example\Factory.csproj", "{3DD86C52-7EF9-4F96-B057-58DFA30CCD27}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Factory", "examples\streaming\factory_example\Factory.csproj", "{2A876DE1-0D84-4FF5-BE82-7C393B6697B7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -269,6 +289,26 @@ Global
{61B42F6B-521C-4A07-B592-54975F4AE2E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{61B42F6B-521C-4A07-B592-54975F4AE2E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{61B42F6B-521C-4A07-B592-54975F4AE2E6}.Release|Any CPU.Build.0 = Release|Any CPU
{8B6FC081-6103-49EB-96A3-84FED3F5181D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8B6FC081-6103-49EB-96A3-84FED3F5181D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8B6FC081-6103-49EB-96A3-84FED3F5181D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8B6FC081-6103-49EB-96A3-84FED3F5181D}.Release|Any CPU.Build.0 = Release|Any CPU
{92C795B8-9002-447E-BFE5-B227D1BA3B22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{92C795B8-9002-447E-BFE5-B227D1BA3B22}.Debug|Any CPU.Build.0 = Debug|Any CPU
{92C795B8-9002-447E-BFE5-B227D1BA3B22}.Release|Any CPU.ActiveCfg = Release|Any CPU
{92C795B8-9002-447E-BFE5-B227D1BA3B22}.Release|Any CPU.Build.0 = Release|Any CPU
{CB254D55-5C90-4EAF-8EE7-5C9C284317E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CB254D55-5C90-4EAF-8EE7-5C9C284317E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CB254D55-5C90-4EAF-8EE7-5C9C284317E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CB254D55-5C90-4EAF-8EE7-5C9C284317E7}.Release|Any CPU.Build.0 = Release|Any CPU
{3DD86C52-7EF9-4F96-B057-58DFA30CCD27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3DD86C52-7EF9-4F96-B057-58DFA30CCD27}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3DD86C52-7EF9-4F96-B057-58DFA30CCD27}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3DD86C52-7EF9-4F96-B057-58DFA30CCD27}.Release|Any CPU.Build.0 = Release|Any CPU
{2A876DE1-0D84-4FF5-BE82-7C393B6697B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2A876DE1-0D84-4FF5-BE82-7C393B6697B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2A876DE1-0D84-4FF5-BE82-7C393B6697B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2A876DE1-0D84-4FF5-BE82-7C393B6697B7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -339,6 +379,16 @@ Global
{8C5A02D8-E18B-4060-A567-A4AACC49B2F6} = {3AC17A9C-30BB-4298-8E5A-4FAE73189821}
{5DFC6330-8303-4045-B186-32B396391D31} = {132EEE99-6194-477A-9416-D7EF173C17FD}
{61B42F6B-521C-4A07-B592-54975F4AE2E6} = {5DFC6330-8303-4045-B186-32B396391D31}
{ACF6E046-747E-440D-BF10-B1E308BF8D60} = {83D6D1F7-97E1-4E35-A0AA-E3ED5977EA72}
{FCFC3960-C92C-43E4-B864-06B9DF621818} = {FA5723B3-74E9-4221-80EF-4833C1C3DD9F}
{6DFDB911-5172-44F0-A3F1-98C301D7B26F} = {77ACBABB-CF6B-4929-957C-480E29646DFD}
{C5428CBF-4741-46E6-A721-AF00716CBAA8} = {50BA802D-603E-4BD2-9A3E-AFDABC3AF43C}
{2B3AF9D0-879A-4B8A-A6EC-0C95F36A1DC5} = {132EEE99-6194-477A-9416-D7EF173C17FD}
{8B6FC081-6103-49EB-96A3-84FED3F5181D} = {ACF6E046-747E-440D-BF10-B1E308BF8D60}
{92C795B8-9002-447E-BFE5-B227D1BA3B22} = {FCFC3960-C92C-43E4-B864-06B9DF621818}
{CB254D55-5C90-4EAF-8EE7-5C9C284317E7} = {6DFDB911-5172-44F0-A3F1-98C301D7B26F}
{3DD86C52-7EF9-4F96-B057-58DFA30CCD27} = {C5428CBF-4741-46E6-A721-AF00716CBAA8}
{2A876DE1-0D84-4FF5-BE82-7C393B6697B7} = {2B3AF9D0-879A-4B8A-A6EC-0C95F36A1DC5}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8D4ABC6D-7126-4EE2-9303-43A954616B2A}
Expand Down
82 changes: 82 additions & 0 deletions Deepgram/ClientFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// 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.Authenticate.v1;
using Deepgram.Clients.Interfaces.v1;

namespace Deepgram;

public static class ClientFactory
{
/// <summary>
/// Create a new AnalyzeClient
/// </summary>
/// <param name="apiKey"></param>
/// <param name="options"></param>
/// <param name="httpId"></param>
/// <returns></returns>
public static IAnalyzeClient CreateAnalyzeClient(string apiKey = "", DeepgramHttpClientOptions? options = null, string? httpId = null)
{
return new AnalyzeClient(apiKey, options, httpId);
}

/// <summary>
/// Create a new AnalyzeClient
/// </summary>
/// <param name="apiKey"></param>
/// <param name="options"></param>
/// <returns></returns>
public static ILiveClient CreateLiveClient(string apiKey = "", DeepgramWsClientOptions? options = null)
{
return new LiveClient(apiKey, options);
}

/// <summary>
/// Create a new LiveClient
/// </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)
{
return new ManageClient(apiKey, options, httpId);
}

/// <summary>
/// Create a new OnPremClient
/// </summary>
/// <param name="apiKey"></param>
/// <param name="options"></param>
/// <param name="httpId"></param>
/// <returns></returns>
public static IOnPremClient CreateOnPremClient(string apiKey = "", DeepgramHttpClientOptions? options = null, string? httpId = null)
{
return new OnPremClient(apiKey, options, httpId);
}

/// <summary>
/// Create a new PreRecordedClient
/// </summary>
/// <param name="apiKey"></param>
/// <param name="options"></param>
/// <param name="httpId"></param>
/// <returns></returns>
public static IPreRecordedClient CreatePreRecordedClient(string apiKey = "", DeepgramHttpClientOptions? options = null, string? httpId = null)
{
return new PreRecordedClient(apiKey, options, httpId);
}

/// <summary>
/// Create a new SpeakClient
/// </summary>
/// <param name="apiKey"></param>
/// <param name="options"></param>
/// <param name="httpId"></param>
/// <returns></returns>
public static ISpeakClient CreateSpeakClient(string apiKey = "", DeepgramHttpClientOptions? options = null, string? httpId = null)
{
return new SpeakClient(apiKey, options, httpId);
}
}
4 changes: 2 additions & 2 deletions Deepgram/Clients/Analyze/v1/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

using System;
using Deepgram.Models.Analyze.v1;
using Deepgram.Models.Authenticate.v1;
using Deepgram.Clients.Interfaces.v1;

namespace Deepgram.Clients.Analyze.v1;

Expand All @@ -14,7 +14,7 @@ namespace Deepgram.Clients.Analyze.v1;
/// <param name="apiKey">Required DeepgramApiKey</param>
/// <param name="deepgramClientOptions"><see cref="DeepgramHttpClientOptions"/> for HttpClient Configuration</param>
public class Client(string? apiKey = null, DeepgramHttpClientOptions? deepgramClientOptions = null, string? httpId = null)
: AbstractRestClient(apiKey, deepgramClientOptions, httpId)
: AbstractRestClient(apiKey, deepgramClientOptions, httpId), IAnalyzeClient
{
#region NoneCallBacks
/// <summary>
Expand Down
74 changes: 74 additions & 0 deletions Deepgram/Clients/Interfaces/v1/IAnalyzeClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// 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.v1;

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>
/// 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);
davidvonthenen marked this conversation as resolved.
Show resolved Hide resolved

/// <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);
davidvonthenen marked this conversation as resolved.
Show resolved Hide resolved
#endregion
}
115 changes: 115 additions & 0 deletions Deepgram/Clients/Interfaces/v1/ILiveClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// 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.v1;

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

public Task Stop(CancellationTokenSource? cancelToken = null);
#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 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 bool Subscribe(EventHandler<MetadataResponse> eventHandler);

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

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

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

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

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

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

#region Send Functions
/// <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);

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

/// <summary>
/// This method sends a text message over the WebSocket connection.
/// </summary>
public void SendMessage(byte[] data);

/// <summary>
/// This method sends a binary message over the WebSocket connection immediately without queueing.
/// </summary>
public void SendBinaryImmediately(byte[] data);

/// <summary>
/// This method sends a text message over the WebSocket connection immediately without queueing.
/// </summary>
public void SendMessageImmediately(byte[] data);
#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
}
Loading
Loading