-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #274 from dvonthenen/factory-interface-clients
Implement Client Interfaces and Factory Methods
- Loading branch information
Showing
31 changed files
with
1,276 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
/// <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); | ||
#endregion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.