diff --git a/Deepgram.Dev.sln b/Deepgram.Dev.sln index b35b9aa8..96418dd4 100644 --- a/Deepgram.Dev.sln +++ b/Deepgram.Dev.sln @@ -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 @@ -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 @@ -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} diff --git a/Deepgram/ClientFactory.cs b/Deepgram/ClientFactory.cs new file mode 100644 index 00000000..71037830 --- /dev/null +++ b/Deepgram/ClientFactory.cs @@ -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 +{ + /// + /// Create a new AnalyzeClient + /// + /// + /// + /// + /// + public static IAnalyzeClient CreateAnalyzeClient(string apiKey = "", DeepgramHttpClientOptions? options = null, string? httpId = null) + { + return new AnalyzeClient(apiKey, options, httpId); + } + + /// + /// Create a new AnalyzeClient + /// + /// + /// + /// + public static ILiveClient CreateLiveClient(string apiKey = "", DeepgramWsClientOptions? options = null) + { + return new LiveClient(apiKey, options); + } + + /// + /// Create a new LiveClient + /// + /// + /// + /// + /// + public static IManageClient CreateManageClient(string apiKey = "", DeepgramHttpClientOptions? options = null, string? httpId = null) + { + return new ManageClient(apiKey, options, httpId); + } + + /// + /// Create a new OnPremClient + /// + /// + /// + /// + /// + public static IOnPremClient CreateOnPremClient(string apiKey = "", DeepgramHttpClientOptions? options = null, string? httpId = null) + { + return new OnPremClient(apiKey, options, httpId); + } + + /// + /// Create a new PreRecordedClient + /// + /// + /// + /// + /// + public static IPreRecordedClient CreatePreRecordedClient(string apiKey = "", DeepgramHttpClientOptions? options = null, string? httpId = null) + { + return new PreRecordedClient(apiKey, options, httpId); + } + + /// + /// Create a new SpeakClient + /// + /// + /// + /// + /// + public static ISpeakClient CreateSpeakClient(string apiKey = "", DeepgramHttpClientOptions? options = null, string? httpId = null) + { + return new SpeakClient(apiKey, options, httpId); + } +} diff --git a/Deepgram/Clients/Analyze/v1/Client.cs b/Deepgram/Clients/Analyze/v1/Client.cs index 40fc4737..36da3432 100644 --- a/Deepgram/Clients/Analyze/v1/Client.cs +++ b/Deepgram/Clients/Analyze/v1/Client.cs @@ -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; @@ -14,7 +14,7 @@ namespace Deepgram.Clients.Analyze.v1; /// Required DeepgramApiKey /// for HttpClient Configuration public class Client(string? apiKey = null, DeepgramHttpClientOptions? deepgramClientOptions = null, string? httpId = null) - : AbstractRestClient(apiKey, deepgramClientOptions, httpId) + : AbstractRestClient(apiKey, deepgramClientOptions, httpId), IAnalyzeClient { #region NoneCallBacks /// diff --git a/Deepgram/Clients/Interfaces/v1/IAnalyzeClient.cs b/Deepgram/Clients/Interfaces/v1/IAnalyzeClient.cs new file mode 100644 index 00000000..ce23933a --- /dev/null +++ b/Deepgram/Clients/Interfaces/v1/IAnalyzeClient.cs @@ -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 + /// + /// Analyze a file by providing a url + /// + /// Url to the file that is to be analyzed + /// Options for the transcription + /// + public Task AnalyzeUrl(UrlSource source, AnalyzeSchema? analyzeSchema, CancellationTokenSource? cancellationToken = default, + Dictionary? addons = null, Dictionary? headers = null); + + /// + /// Analyzes a file using the provided byte array + /// + /// file is the form of a byte[] + /// Options for the transcription + /// + public Task AnalyzeFile(byte[] source, AnalyzeSchema? analyzeSchema, CancellationTokenSource? cancellationToken = default, + Dictionary? addons = null, Dictionary? headers = null); + + /// + /// Analyzes a file using the provided stream + /// + /// file is the form of a stream + /// Options for the transcription + /// + public Task AnalyzeFile(Stream source, AnalyzeSchema? analyzeSchema, CancellationTokenSource? cancellationToken = default, + Dictionary? addons = null, Dictionary? headers = null); + #endregion + + #region CallBack Methods + /// + /// Analyzes a file using the provided byte array and providing a CallBack + /// + /// file is the form of a byte[] + /// CallBack url + /// Options for the transcription + /// + public Task AnalyzeFileCallBack(byte[] source, string? callBack, AnalyzeSchema? analyzeSchema, + CancellationTokenSource? cancellationToken = default, Dictionary? addons = null, + Dictionary? headers = null); + + /// + /// Analyzes a file using the provided stream and providing a CallBack + /// + /// file is the form of a stream + /// CallBack url + /// Options for the transcription + /// + public Task AnalyzeFileCallBack(Stream source, string? callBack, AnalyzeSchema? analyzeSchema, + CancellationTokenSource? cancellationToken = default, Dictionary? addons = null, + Dictionary? headers = null); + + /// + /// Analyze a file by providing a url and a CallBack + /// + /// Url to the file that is to be analyzed + /// CallBack url + /// Options for the transcription + /// + public Task AnalyzeUrlCallBack(UrlSource source, string? callBack, AnalyzeSchema? analyzeSchema, + CancellationTokenSource? cancellationToken = default, Dictionary? addons = null, + Dictionary? headers = null); + #endregion +} diff --git a/Deepgram/Clients/Interfaces/v1/ILiveClient.cs b/Deepgram/Clients/Interfaces/v1/ILiveClient.cs new file mode 100644 index 00000000..c0b3d37e --- /dev/null +++ b/Deepgram/Clients/Interfaces/v1/ILiveClient.cs @@ -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; + +/// +/// Implements version 1 of the Live Client. +/// +public interface ILiveClient +{ + #region Connect and Disconnect + public Task Connect(LiveSchema options, CancellationTokenSource? cancelToken = null, Dictionary? addons = null, + Dictionary? headers = null); + + public Task Stop(CancellationTokenSource? cancelToken = null); + #endregion + + #region Subscribe Event + /// + /// Subscribe to an Open event from the Deepgram API + /// + /// + /// True if successful + public bool Subscribe(EventHandler eventHandler); + + /// + /// Subscribe to a Metadata event from the Deepgram API + /// + /// + /// True if successful + public bool Subscribe(EventHandler eventHandler); + + /// + /// Subscribe to a Results event from the Deepgram API + /// + /// True if successful + public bool Subscribe(EventHandler eventHandler); + + /// + /// Subscribe to an UtteranceEnd event from the Deepgram API + /// + /// True if successful + public bool Subscribe(EventHandler eventHandler); + + /// + /// Subscribe to a SpeechStarted event from the Deepgram API + /// + /// True if successful + public bool Subscribe(EventHandler eventHandler); + + /// + /// Subscribe to a Close event from the Deepgram API + /// + /// True if successful + public bool Subscribe(EventHandler eventHandler); + + /// + /// Subscribe to an Unhandled event from the Deepgram API + /// + /// True if successful + public bool Subscribe(EventHandler eventHandler); + + /// + /// Subscribe to an Error event from the Deepgram API + /// + /// True if successful + public bool Subscribe(EventHandler eventHandler); + #endregion + + #region Send Functions + /// + /// Sends a binary message over the WebSocket connection. + /// + /// The data to be sent over the WebSocket. + public void Send(byte[] data); + + /// + /// This method sends a binary message over the WebSocket connection. + /// + /// + public void SendBinary(byte[] data); + + /// + /// This method sends a text message over the WebSocket connection. + /// + public void SendMessage(byte[] data); + + /// + /// This method sends a binary message over the WebSocket connection immediately without queueing. + /// + public void SendBinaryImmediately(byte[] data); + + /// + /// This method sends a text message over the WebSocket connection immediately without queueing. + /// + public void SendMessageImmediately(byte[] data); + #endregion + + #region Helpers + /// + /// Retrieves the connection state of the WebSocket + /// + /// Returns the connection state of the WebSocket + public WebSocketState State(); + + /// + /// Indicates whether the WebSocket is connected + /// + /// Returns true if the WebSocket is connected + public bool IsConnected(); + #endregion +} diff --git a/Deepgram/Clients/Interfaces/v1/IManageClient.cs b/Deepgram/Clients/Interfaces/v1/IManageClient.cs new file mode 100644 index 00000000..7fc28c6a --- /dev/null +++ b/Deepgram/Clients/Interfaces/v1/IManageClient.cs @@ -0,0 +1,219 @@ +// 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.v1; + +/// +/// Implements version 1 of the Manage Client. +/// +/// Required DeepgramApiKey +/// for HttpClient Configuration +public interface IManageClient +{ + #region Projects + /// + /// Gets projects associated to ApiKey + /// + /// + public Task GetProjects(CancellationTokenSource? cancellationToken = default, + Dictionary? addons = null, Dictionary? headers = null); + + /// + /// Gets project associated with project Id + /// + /// Id of Project + /// + public Task GetProject(string projectId, CancellationTokenSource? cancellationToken = default, + Dictionary? addons = null, Dictionary? headers = null); + + /// + /// Update a project associated with the projectID + /// + /// ID of project + /// for project + /// + // USES PATCH + public Task UpdateProject(string projectId, ProjectSchema updateProjectSchema, CancellationTokenSource? cancellationToken = default, + Dictionary? addons = null, Dictionary? headers = null); + + /// + /// Deletes a project, no response will be returned + /// + /// Id of project + // No response expected + public Task DeleteProject(string projectId, CancellationTokenSource? cancellationToken = default, + Dictionary? addons = null, Dictionary? headers = null); + + /// + /// leave project associated with the project Id + /// + /// Id of project + /// + public Task LeaveProject(string projectId, CancellationTokenSource? cancellationToken = default, + Dictionary? addons = null, Dictionary? headers = null); + #endregion + + #region ProjectKeys + /// + /// Get the keys associated with the project + /// + /// Id of project + /// + public Task GetKeys(string projectId, CancellationTokenSource? cancellationToken = default, + Dictionary? addons = null, Dictionary? headers = null); + + /// + /// Get details of key associated with the key ID + /// + /// Id of project + /// Id of key + /// + public Task GetKey(string projectId, string keyId, CancellationTokenSource? cancellationToken = default, + Dictionary? addons = null, Dictionary? headers = null); + + /// + /// Create a key in the associated project + /// + /// Id of project + /// for the key to be created + /// + public Task CreateKey(string projectId, KeySchema keySchema, CancellationTokenSource? cancellationToken = default, + Dictionary? addons = null, Dictionary? headers = null); + + /// + /// Remove key from project, No response returned + /// + /// Id of project + /// Id of key + // Nothing being returned + public Task DeleteKey(string projectId, string keyId, CancellationTokenSource? cancellationToken = default, + Dictionary? addons = null, Dictionary? headers = null); + #endregion + + #region ProjectInvites + /// + /// Get any invites that are associated with project + /// + /// Id of project + /// + public Task GetInvites(string projectId, CancellationTokenSource? cancellationToken = default, + Dictionary? addons = null, Dictionary? headers = null); + + /// + /// Delete a project invite that has been sent + /// + /// Id of project + /// email of the invite to be removed + //no response expected + public Task DeleteInvite(string projectId, string email, CancellationTokenSource? cancellationToken = default, + Dictionary? addons = null, Dictionary? headers = null); + + /// + /// Send a invite to the associated project + /// + /// Id of project + /// for a invite to project + /// + public Task SendInvite(string projectId, InviteSchema inviteSchema, CancellationTokenSource? cancellationToken = default, + Dictionary? addons = null, Dictionary? headers = null); + #endregion + + #region Members + /// + /// Get the members associated with the project + /// + /// Id of project + /// + public Task GetMembers(string projectId, CancellationTokenSource? cancellationToken = default, + Dictionary? addons = null, Dictionary? headers = null); + + /// + /// Get the scopes associated with member + /// + /// Id of project + /// Id of member + /// + public Task GetMemberScopes(string projectId, string memberId, CancellationTokenSource? cancellationToken = default, + Dictionary? addons = null, Dictionary? headers = null); + + /// + /// Update the scopes fot the member + /// + /// Id of project + /// Id of member + /// updates scope options for member + /// + public Task UpdateMemberScope(string projectId, string memberId, MemberScopeSchema scopeSchema, + CancellationTokenSource? cancellationToken = default, Dictionary? addons = null, + Dictionary? headers = null); + + /// + /// Remove member from project, there is no response + /// + /// Id of project + /// Id of member + //No response expected + public Task RemoveMember(string projectId, string memberId, CancellationTokenSource? cancellationToken = default, + Dictionary? addons = null, Dictionary? headers = null); + #endregion + + #region Usage + /// + /// Get usage request associated with the project + /// + /// Id of project + /// Project usage request options + /// + public Task GetUsageRequests(string projectId, UsageRequestsSchema usageRequestsSchema, + CancellationTokenSource? cancellationToken = default, Dictionary? addons = null, Dictionary? headers = null); + + /// + /// Get the details associated with the requestID + /// + /// Id of project + /// Id of request + /// + public Task GetUsageRequest(string projectId, string requestId, CancellationTokenSource? cancellationToken = default, + Dictionary? addons = null, Dictionary? headers = null); + + /// + /// Gets a summary of usage + /// + /// Id of project + /// Usage summary options + /// + public Task GetUsageSummary(string projectId, UsageSummarySchema summarySchema, + CancellationTokenSource? cancellationToken = default, Dictionary? addons = null, Dictionary? headers = null); + + /// + /// Get usage fields + /// + /// Id of project + /// Project usage request field options + /// + public Task GetUsageFields(string projectId, UsageFieldsSchema fieldsSchema, + CancellationTokenSource? cancellationToken = default, Dictionary? addons = null, Dictionary? headers = null); + #endregion + + #region Balances + /// + /// Gets a list of balances + /// + /// Id of project + /// + public Task GetBalances(string projectId, CancellationTokenSource? cancellationToken = default, + Dictionary? addons = null, Dictionary? headers = null); + + /// + /// Get the balance details associated with the balance id + /// + /// Id of project + /// Id of balance + /// + public Task GetBalance(string projectId, string balanceId, CancellationTokenSource? cancellationToken = default, + Dictionary? addons = null, Dictionary? headers = null); + #endregion +} diff --git a/Deepgram/Clients/Interfaces/v1/IOnPremClient.cs b/Deepgram/Clients/Interfaces/v1/IOnPremClient.cs new file mode 100644 index 00000000..c8dafb5e --- /dev/null +++ b/Deepgram/Clients/Interfaces/v1/IOnPremClient.cs @@ -0,0 +1,50 @@ +// 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.OnPrem.v1; + +namespace Deepgram.Clients.Interfaces.v1; + +/// +/// Implements version 1 of the OnPrem Client. +/// +/// Required DeepgramApiKey +/// for HttpClient Configuration +public interface IOnPremClient +{ + /// + /// get a list of credentials associated with project + /// + /// Id of project + /// + public Task ListCredentials(string projectId, CancellationTokenSource? cancellationToken = default, + Dictionary? addons = null, Dictionary? headers = null); + + /// + /// Get credentials for the project that is associated with credential ID + /// + /// Id of project + /// Id of credentials + /// + public Task GetCredentials(string projectId, string credentialsId, CancellationTokenSource? cancellationToken = default, + Dictionary? addons = null, Dictionary? headers = null); + + /// + /// Remove credentials in the project associated with the credentials ID + /// + /// Id of project + /// Id of credentials + /// + public Task DeleteCredentials(string projectId, string credentialsId, CancellationTokenSource? cancellationToken = default, + Dictionary? addons = null, Dictionary? headers = null); + + /// + /// Create credentials for the associated projects + /// + /// Id of project + /// for credentials to be created + /// + public Task CreateCredentials(string projectId, CredentialsSchema credentialsSchema, + CancellationTokenSource? cancellationToken = default, Dictionary? addons = null, Dictionary? headers = null); +} diff --git a/Deepgram/Clients/Interfaces/v1/IPreRecordedClient.cs b/Deepgram/Clients/Interfaces/v1/IPreRecordedClient.cs new file mode 100644 index 00000000..af7729e0 --- /dev/null +++ b/Deepgram/Clients/Interfaces/v1/IPreRecordedClient.cs @@ -0,0 +1,81 @@ +// 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.PreRecorded.v1; + +namespace Deepgram.Clients.Interfaces.v1; + +/// +/// Implements version 1 of the Analyze Client. +/// +/// Required DeepgramApiKey +/// for HttpClient Configuration +public interface IPreRecordedClient + +{ + #region NoneCallBacks + /// + /// Transcribe a file by providing a url + /// + /// Url to the file that is to be transcribed + /// Options for the transcription + /// + public Task TranscribeUrl(UrlSource source, PrerecordedSchema? prerecordedSchema, + CancellationTokenSource? cancellationToken = default, Dictionary? addons = null, Dictionary? headers = null); + + /// + /// Transcribes a file using the provided byte array + /// + /// file is the form of a byte[] + /// Options for the transcription + /// + public Task TranscribeFile(byte[] source, PrerecordedSchema? prerecordedSchema, + CancellationTokenSource? cancellationToken = default, Dictionary? addons = null, Dictionary? headers = null); + + /// + /// Transcribes a file using the provided stream + /// + /// file is the form of a streasm + /// Options for the transcription + /// + public Task TranscribeFile(Stream source, PrerecordedSchema? prerecordedSchema, + CancellationTokenSource? cancellationToken = default, Dictionary? addons = null, + Dictionary? headers = null); + #endregion + + #region CallBack Methods + /// + /// Transcribes a file using the provided byte array and providing a CallBack + /// + /// file is the form of a byte[] + /// CallBack url + /// Options for the transcription + /// + public Task TranscribeFileCallBack(byte[] source, string? callBack, PrerecordedSchema? prerecordedSchema, + CancellationTokenSource? cancellationToken = default, Dictionary? addons = null, + Dictionary? headers = null); + + /// + /// Transcribes a file using the provided stream and providing a CallBack + /// + /// file is the form of a stream + /// CallBack url + /// Options for the transcription + /// + public Task TranscribeFileCallBack(Stream source, string? callBack, PrerecordedSchema? prerecordedSchema, + CancellationTokenSource? cancellationToken = default, Dictionary? addons = null, + Dictionary? headers = null); + + /// + /// Transcribe a file by providing a url and a CallBack + /// + /// Url to the file that is to be transcribed + /// CallBack url + /// Options for the transcription + /// + public Task TranscribeUrlCallBack(UrlSource source, string? callBack, PrerecordedSchema? prerecordedSchema, + CancellationTokenSource? cancellationToken = default, Dictionary? addons = null, + Dictionary? headers = null); + #endregion +} diff --git a/Deepgram/Clients/Interfaces/v1/ISpeakClient.cs b/Deepgram/Clients/Interfaces/v1/ISpeakClient.cs new file mode 100644 index 00000000..e3bfa155 --- /dev/null +++ b/Deepgram/Clients/Interfaces/v1/ISpeakClient.cs @@ -0,0 +1,41 @@ +// 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; + +namespace Deepgram.Clients.Interfaces.v1; + +/// +/// Implements version 1 of the Speak Client. +/// +/// Required DeepgramApiKey +/// for HttpClient Configuration +public interface ISpeakClient +{ + #region NoneCallBacks + /// + /// Speaks a file using the provided stream + /// + /// file is the form of a stream + /// Options for the transcription + /// + public Task ToStream(TextSource source, SpeakSchema? speakSchema, CancellationTokenSource? cancellationToken = default, + Dictionary? addons = null, Dictionary? headers = null); + + public Task ToFile(TextSource source, string filename, SpeakSchema? speakSchema, CancellationTokenSource? cancellationToken = default, + Dictionary? addons = null, Dictionary? headers = null); + #endregion + + #region CallBack Methods + /// + /// Speaks a file using the provided byte array and providing a CallBack + /// + /// file is the form of a byte[] + /// CallBack url + /// Options for the transcription + /// + public Task StreamCallBack(TextSource source, string? callBack, SpeakSchema? speakSchema, CancellationTokenSource? cancellationToken = default, + Dictionary? addons = null, Dictionary? headers = null); + #endregion +} diff --git a/Deepgram/Clients/Live/v1/Client.cs b/Deepgram/Clients/Live/v1/Client.cs index c73e51dc..db1ba832 100644 --- a/Deepgram/Clients/Live/v1/Client.cs +++ b/Deepgram/Clients/Live/v1/Client.cs @@ -2,17 +2,17 @@ // 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 System.Threading; + using Deepgram.Models.Authenticate.v1; using Deepgram.Models.Live.v1; +using Deepgram.Clients.Interfaces.v1; namespace Deepgram.Clients.Live.v1; /// /// Implements version 1 of the Live Client. /// -public class Client : Attribute, IDisposable +public class Client : IDisposable, ILiveClient { #region Fields private readonly DeepgramWsClientOptions _deepgramClientOptions; diff --git a/Deepgram/Clients/Manage/v1/Client.cs b/Deepgram/Clients/Manage/v1/Client.cs index ec4c97b5..17e6d519 100644 --- a/Deepgram/Clients/Manage/v1/Client.cs +++ b/Deepgram/Clients/Manage/v1/Client.cs @@ -4,6 +4,7 @@ using Deepgram.Models.Authenticate.v1; using Deepgram.Models.Manage.v1; +using Deepgram.Clients.Interfaces.v1; namespace Deepgram.Clients.Manage.v1; @@ -13,7 +14,7 @@ namespace Deepgram.Clients.Manage.v1; /// Required DeepgramApiKey /// for HttpClient Configuration public class Client(string? apiKey = null, DeepgramHttpClientOptions? deepgramClientOptions = null, string? httpId = null) - : AbstractRestClient(apiKey, deepgramClientOptions, httpId) + : AbstractRestClient(apiKey, deepgramClientOptions, httpId), IManageClient { #region Projects /// diff --git a/Deepgram/Clients/OnPrem/v1/Client.cs b/Deepgram/Clients/OnPrem/v1/Client.cs index f1780f47..d8c4b2d6 100644 --- a/Deepgram/Clients/OnPrem/v1/Client.cs +++ b/Deepgram/Clients/OnPrem/v1/Client.cs @@ -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.Authenticate.v1; using Deepgram.Models.OnPrem.v1; +using Deepgram.Clients.Interfaces.v1; namespace Deepgram.Clients.OnPrem.v1; @@ -14,7 +14,7 @@ namespace Deepgram.Clients.OnPrem.v1; /// Required DeepgramApiKey /// for HttpClient Configuration public class Client(string? apiKey = null, DeepgramHttpClientOptions? deepgramClientOptions = null, string? httpId = null) - : AbstractRestClient(apiKey, deepgramClientOptions, httpId) + : AbstractRestClient(apiKey, deepgramClientOptions, httpId), IOnPremClient { /// /// get a list of credentials associated with project diff --git a/Deepgram/Clients/PreRecorded/v1/Client.cs b/Deepgram/Clients/PreRecorded/v1/Client.cs index 3da81953..596d0088 100644 --- a/Deepgram/Clients/PreRecorded/v1/Client.cs +++ b/Deepgram/Clients/PreRecorded/v1/Client.cs @@ -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.Authenticate.v1; using Deepgram.Models.PreRecorded.v1; +using Deepgram.Clients.Interfaces.v1; namespace Deepgram.Clients.PreRecorded.v1; @@ -14,7 +14,7 @@ namespace Deepgram.Clients.PreRecorded.v1; /// Required DeepgramApiKey /// for HttpClient Configuration public class Client(string? apiKey = null, DeepgramHttpClientOptions? deepgramClientOptions = null, string? httpId = null) - : AbstractRestClient(apiKey, deepgramClientOptions, httpId) + : AbstractRestClient(apiKey, deepgramClientOptions, httpId), IPreRecordedClient { #region NoneCallBacks diff --git a/Deepgram/Clients/Speak/v1/Client.cs b/Deepgram/Clients/Speak/v1/Client.cs index 9c86f75c..ca58c4a1 100644 --- a/Deepgram/Clients/Speak/v1/Client.cs +++ b/Deepgram/Clients/Speak/v1/Client.cs @@ -4,7 +4,7 @@ using Deepgram.Models.Speak.v1; using Deepgram.Models.Authenticate.v1; -using System; +using Deepgram.Clients.Interfaces.v1; namespace Deepgram.Clients.Speak.v1; @@ -14,7 +14,7 @@ namespace Deepgram.Clients.Speak.v1; /// Required DeepgramApiKey /// for HttpClient Configuration public class Client(string? apiKey = null, DeepgramHttpClientOptions? deepgramClientOptions = null, string? httpId = null) - : AbstractRestClient(apiKey, deepgramClientOptions, httpId) + : AbstractRestClient(apiKey, deepgramClientOptions, httpId), ISpeakClient { #region NoneCallBacks /// @@ -94,8 +94,7 @@ public async Task ToStream(TextSource source, SpeakSchema? speakSc } public async Task ToFile(TextSource source, string filename, SpeakSchema? speakSchema, CancellationTokenSource? cancellationToken = default, - Dictionary? addons = null, Dictionary? headers = null - ) + Dictionary? addons = null, Dictionary? headers = null) { Log.Verbose("Client.ToFile", "ENTER"); Log.Information("ToFile", $"filename: {filename}"); diff --git a/examples/analyze/factory_example/Factory.csproj b/examples/analyze/factory_example/Factory.csproj new file mode 100644 index 00000000..d0ea3e2e --- /dev/null +++ b/examples/analyze/factory_example/Factory.csproj @@ -0,0 +1,28 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + + + + + + + + + + + Always + + + + diff --git a/examples/analyze/factory_example/Program.cs b/examples/analyze/factory_example/Program.cs new file mode 100644 index 00000000..e5701948 --- /dev/null +++ b/examples/analyze/factory_example/Program.cs @@ -0,0 +1,59 @@ +// 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 System.Text.Json; + +using Deepgram.Models.Analyze.v1; +using Deepgram.Logger; + +namespace PreRecorded +{ + class Program + { + static async Task Main(string[] args) + { + // Initialize Library with default logging + // Normal logging is "Info" level + Library.Initialize(); + // OR to set logging level + //Library.Initialize(LogLevel.Debug); + + // JSON options + JsonSerializerOptions options = new(JsonSerializerDefaults.Web) + { + WriteIndented = true + }; + + // use the client factory with a API Key set with the "DEEPGRAM_API_KEY" environment variable + var deepgramClient = ClientFactory.CreateAnalyzeClient(); + + // check to see if the file exists + if (!File.Exists(@"conversation.txt")) + { + Console.WriteLine("Error: File 'conversation.txt' not found."); + return; + } + + // increase timeout to 60 seconds + CancellationTokenSource cancelToken = new CancellationTokenSource(); + cancelToken.CancelAfter(TimeSpan.FromSeconds(120)); + + var audioData = File.ReadAllBytes(@"conversation.txt"); + var response = await deepgramClient.AnalyzeFile( + audioData, + new AnalyzeSchema() + { + Language = "en", + Intents = true, + }, + cancelToken); + + Console.WriteLine($"\n\n{JsonSerializer.Serialize(response, options)}\n\n"); + Console.ReadKey(); + + // Teardown Library + Library.Terminate(); + } + } +} \ No newline at end of file diff --git a/examples/analyze/factory_example/conversation.txt b/examples/analyze/factory_example/conversation.txt new file mode 100644 index 00000000..2af89e08 --- /dev/null +++ b/examples/analyze/factory_example/conversation.txt @@ -0,0 +1,71 @@ +Meet Deepgram Aura: real-time text-to-speech for real-time AI agents +---------- +It’s been a year since large language models (LLMs) seemingly went mainstream overnight (Happy Birthday, ChatGPT!!!), and the world has witnessed both rapid development of these technologies and immense interest in their potential. We believe that we have reached an inflection point where voice-based interfaces will be the primary means to accessing LLMs and the experiences they unlock. Here are a few recent signals in support of our thesis: + +- Good old fashioned voice notes are enjoying a healthy resurgence. + +- According to a recent survey, a majority of respondents stated phone calls are still their preferred communication channel for resolving customer service issues. + +- An emerging boom in wearable devices equipped with continuous listening and speech AI technology is gaining steam. + +- OpenAI recently enabled voice interactions in ChatGPT. + +- A wave of interest in voice-first experiences and tools is sweeping across brands, investors, and tech companies. + +Thanks to ChatGPT and the advent of the LLM era, the conversational AI tech stack has advanced sufficiently to support productive (not frustrating) voice-powered AI assistants and agents that can interact with humans in a natural manner. We have already observed this from our most innovative customers who are actively turning to these technologies to build a diverse range of AI agents for voice ordering systems, interview bots, personal AI assistants, automated drive-thru tellers, and autonomous sales and customer service agents. + +While these AI agents hold immense potential, many customers have expressed their dissatisfaction with the current crop of voice AI vendors, citing roadblocks related to speed, cost, reliability, and conversational quality. That’s why we’re excited to introduce our own text-to-speech (TTS) API, Deepgram Aura, built for real-time, conversational voice AI agents. + +Whether used on its own or in conjunction with our industry-leading Nova-2 speech-to-text API, we’ll soon provide developers with a complete speech AI platform, giving them the essential building blocks they need to build high throughput, real-time AI agents of the future. + +We are thrilled about the progress our initial group of developers has made using Aura, so much so that we are extending limited access to a select few partners who will be free to begin integrating with Aura immediately. With their feedback, we’ll continue to enhance our suite of voices and API features, as well as ensure a smooth launch of their production-grade applications. + + +What Customers Want +---------- +I feel the need, the need for speed +What we’ve heard from many of our customers and partners is that voice AI technology today caters to two main areas: high production or high throughput. + +High Production is all about crafting the perfect voice. It's used in projects where every tone and inflection matters, like in video games or audiobooks, to really bring a scene or story to life. Here, voice quality is king, with creators investing hours to fine-tune every detail for a powerful emotional impact. The primary benefit is the ability to swap out a high-paid voice actor with AI where you have more dynamic control over what’s being said while also achieving some cost savings. But these use cases are more specialized and represent just a sliver of the overall voice AI opportunity. + +On the flip side, High Throughput is about handling many quick, one-off interactions for real-time conversations at scale. Think fast food ordering, booking appointments, or inquiring about the latest deals at a car dealership. These tasks are relevant to just about everyone on the planet, and they require fast, efficient text-to-speech conversion for an AI agent to fulfill them. While voice quality is still important to keep users engaged, quality here is more about the naturalness of the flow of conversation and less about sounding like Morgan Freeman. But the primary focus for most customers in this category is on improving customer outcomes, meaning speed and efficiency are must-haves for ensuring these everyday exchanges are smooth and reliable at high volume. + +"Deepgram showed me less than 200ms latency today. That's the fastest text-to-speech I’ve ever seen. And our customers would be more than satisfied with the conversation quality." + +Jordan Dearsley, Co-founder at Vapi + +Although high production use cases seem to be well-served with UI-centric production tools, high throughput, real-time use cases still mostly rely on APIs provided by the major cloud providers. And our customers have been telling us that they’ve been falling short, with insufficient quality for a good user experience, too much latency to make real-time use cases work, and costs too expensive to operate at scale. + + +More human than human +---------- +With Aura, we’ll give realistic voices to AI agents. Our goal is to craft text-to-speech capabilities that mirror natural human conversations, including timely responses, the incorporation of natural speech fillers like 'um' and 'uh' during contemplation, and the modulation of tone and emotion according to the conversational context. We aim to incorporate laughter and other speech nuances as well. Furthermore, we are dedicated to tailoring these voices to their specific applications, ensuring they remain composed and articulate, particularly in enunciating account numbers and business names with precision. + +"I don’t really consider Azure and the other guys anymore because the voices sound so robotic." +Jordan Dearsley, Co-founder at Vapi + +In blind evaluation trials conducted for benchmarking, early versions of Aura have consistently been rated as sounding more human than prominent alternatives, even outranking human speakers for various audio clips more often than not on average. We were pleasantly surprised by these results (stay tuned for a future post containing comprehensive benchmarks for speed and quality soon!), so much so that we’re accelerating our development timeline and publicly announcing today’s waitlist expansion. + +Here are some sample clips generated by one of the earliest iterations of Aura. The quality and overall performance will continue to improve with additional model training and refinement. We encourage you to give them a listen and note the naturalness of their cadence, rhythm, and tone in the flow of conversation with another human. + + +Our Approach +---------- +For nearly a decade, we’ve worked tirelessly to advance the art of the possible in speech recognition and spoken language understanding. Along the way, we’ve transcribed trillions of spoken words into highly accurate transcriptions. Our model research team has developed novel transformer architectures equipped to deal with the nuances of conversational audio–across different languages, accents, and dialects, while handling disfluencies and the changing rhythms, tones, cadences, and inflections that occur in natural, back-and-forth conversations. + +And all the while, we’ve purposefully built our models under limited constraints to optimize their speed and efficiency. With support for dozens of languages and custom model training, our technical team has trained and deployed thousands of speech AI models (more than anybody else) which we operate and manage for our customers each day using our own computing infrastructure. + +We also have our own in-house data labeling and data ops team with years of experience building bespoke workflows to record, store, and transfer vast amounts of audio in order to label it and continuously grow our bank of high-quality data (millions of hours and counting) used in our model training. + +These combined experiences have made us experts in processing and modeling speech audio, especially in support of streaming use cases with our real-time STT models. Our customers have been asking if we could apply the same approach for TTS, and we can. + +So what can you expect from Aura? Delivering the same market-leading value and performance as Nova-2 does for STT. Aura is built to be the panacea for speed, quality, and efficiency–the fastest of the high-quality options, and the best quality of the fast ones. And that’s really what end users need and what our customers have been asking us to build. + +"Deepgram is a valued partner, providing our customers with high throughput speech-to-text that delivers unrivaled performance without tradeoffs between quality, speed, and cost. We're excited to see Deepgram extend their speech AI platform and bring this approach to the text-to-speech market." - Richard Dumas, VP AI Product Strategy at Five9 + + +What's Next +---------- +As we’ve discussed, scaled voice agents are a high throughput use case, and we believe their success will ultimately depend on a unified approach to audio, one that strikes the right balance between natural voice quality, responsiveness, and cost-efficiency. And with Aura, we’re just getting started. We’re looking forward to continuing to work with customers like Asurion and partners like Five9 across speech-to-text AND text-to-speech as we help them define the future of AI agents, and we invite you to join us on this journey. + +We expect to release generally early next year, but if you’re working on any real-time AI agent use cases, join our waitlist today to jumpstart your development in production as we continue to refine our model and API features with your direct feedback. \ No newline at end of file diff --git a/examples/manage/factory_example/Factory.csproj b/examples/manage/factory_example/Factory.csproj new file mode 100644 index 00000000..33d8f4ee --- /dev/null +++ b/examples/manage/factory_example/Factory.csproj @@ -0,0 +1,22 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + + + + + + + + + diff --git a/examples/manage/factory_example/Program.cs b/examples/manage/factory_example/Program.cs new file mode 100644 index 00000000..146b1f77 --- /dev/null +++ b/examples/manage/factory_example/Program.cs @@ -0,0 +1,78 @@ +// 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 System.Text.Json; + +using Deepgram.Logger; +using Deepgram.Models.Manage.v1; + +namespace SampleApp +{ + class Program + { + static async Task Main(string[] args) + { + // Initialize Library with default logging + // Normal logging is "Info" level + Library.Initialize(); + // OR very chatty logging + //Library.Initialize(LogLevel.Debug); // LogLevel.Default, LogLevel.Debug, LogLevel.Verbose + + // JSON options + JsonSerializerOptions options = new(JsonSerializerDefaults.Web) + { + WriteIndented = true + }; + + // use the client factory with a API Key set with the "DEEPGRAM_API_KEY" environment variable + var deepgramClient = ClientFactory.CreateManageClient(); + + var response = await deepgramClient.GetProjects(); + if (response == null) + { + Console.WriteLine("No projects found."); + return; + } + Console.WriteLine($"\n\n{JsonSerializer.Serialize(response, options)}\n\n"); + + var projectId = ""; + foreach (var project in response.Projects) + { + Console.WriteLine($"Using Project ID: {project.ProjectId}"); + projectId = project.ProjectId; + break; + } + + var balanacesResponse = deepgramClient.GetBalances(projectId); + if (balanacesResponse == null) + { + Console.WriteLine("\n\nNo balance found.\n\n"); + return; + } + Console.WriteLine($"\n\n{JsonSerializer.Serialize(balanacesResponse, options)}\n\n"); + + string balanceId = ""; + foreach (var balance in balanacesResponse.Result.Balances) + { + Console.WriteLine($"Using Balance ID: {balance.BalanceId}"); + balanceId = balance.BalanceId; + break; + } + + var balanceResponse = deepgramClient.GetBalance(projectId, balanceId); + if (balanceResponse == null) + { + Console.WriteLine("\n\nNo balance found.\n\n"); + return; + } + Console.WriteLine($"\n\n{JsonSerializer.Serialize(balanceResponse, options)}\n\n"); + + Console.WriteLine("\n\nPress any key to exit."); + Console.ReadKey(); + + // Teardown Library + Library.Terminate(); + } + } +} \ No newline at end of file diff --git a/examples/prerecorded/factory_example/Bueller-Life-moves-pretty-fast.wav b/examples/prerecorded/factory_example/Bueller-Life-moves-pretty-fast.wav new file mode 100644 index 00000000..ca08d921 Binary files /dev/null and b/examples/prerecorded/factory_example/Bueller-Life-moves-pretty-fast.wav differ diff --git a/examples/prerecorded/factory_example/Factory.csproj b/examples/prerecorded/factory_example/Factory.csproj new file mode 100644 index 00000000..7b0c8f9c --- /dev/null +++ b/examples/prerecorded/factory_example/Factory.csproj @@ -0,0 +1,28 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + + + + + + + + + + + Always + + + + diff --git a/examples/prerecorded/factory_example/Program.cs b/examples/prerecorded/factory_example/Program.cs new file mode 100644 index 00000000..3b032a1c --- /dev/null +++ b/examples/prerecorded/factory_example/Program.cs @@ -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 + +using System.Text.Json; + +using Deepgram.Logger; +using Deepgram.Models.Authenticate.v1; +using Deepgram.Models.PreRecorded.v1; + +namespace PreRecorded +{ + class Program + { + static async Task Main(string[] args) + { + // Initialize Library with default logging + // Normal logging is "Info" level + //Library.Initialize(); + // OR very chatty logging + Library.Initialize(LogLevel.Debug); // LogLevel.Default, LogLevel.Debug, LogLevel.Verbose + + // JSON options + JsonSerializerOptions options = new(JsonSerializerDefaults.Web) + { + WriteIndented = true + }; + + // use the client factory with a API Key set with the "DEEPGRAM_API_KEY" environment variable + var deepgramClient = ClientFactory.CreatePreRecordedClient(); + + // check to see if the file exists + if (!File.Exists(@"Bueller-Life-moves-pretty-fast.wav")) + { + Console.WriteLine("Error: File 'Bueller-Life-moves-pretty-fast.wav' not found."); + return; + } + + // increase timeout to a very large value + CancellationTokenSource cancelToken = new CancellationTokenSource(); + cancelToken.CancelAfter(3600000); + + var audioData = File.ReadAllBytes(@"Bueller-Life-moves-pretty-fast.wav"); + var response = await deepgramClient.TranscribeFile( + audioData, + new PrerecordedSchema() + { + Model = "nova-2", + Punctuate = true, + }, + cancelToken); + + Console.WriteLine($"\n\n{JsonSerializer.Serialize(response, options)}\n\n"); + Console.WriteLine("Press any key to exit..."); + Console.ReadKey(); + + // Teardown Library + Library.Terminate(); + } + } +} \ No newline at end of file diff --git a/examples/speak/file/factory_example/Factory.csproj b/examples/speak/file/factory_example/Factory.csproj new file mode 100644 index 00000000..87509ec4 --- /dev/null +++ b/examples/speak/file/factory_example/Factory.csproj @@ -0,0 +1,19 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + + + + + + diff --git a/examples/speak/file/factory_example/Program.cs b/examples/speak/file/factory_example/Program.cs new file mode 100644 index 00000000..63e2a2e0 --- /dev/null +++ b/examples/speak/file/factory_example/Program.cs @@ -0,0 +1,48 @@ +// 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 System.Text.Json; + +using Deepgram; +using Deepgram.Models.Speak.v1; +using Deepgram.Logger; + +namespace SampleApp +{ + class Program + { + static async Task Main(string[] args) + { + // Initialize Library with default logging + // Normal logging is "Info" level + Library.Initialize(); + // OR very chatty logging + //Library.Initialize(LogLevel.Debug); // LogLevel.Default, LogLevel.Debug, LogLevel.Verbose + + // JSON options + JsonSerializerOptions options = new(JsonSerializerDefaults.Web) + { + WriteIndented = true + }; + + // use the client factory with a API Key set with the "DEEPGRAM_API_KEY" environment variable + var deepgramClient = ClientFactory.CreateSpeakClient(); + + var response = await deepgramClient.ToFile( + new TextSource("Hello World!"), + "test.mp3", + new SpeakSchema() + { + Model = "aura-asteria-en", + }); + + //Console.WriteLine(response); + Console.WriteLine(JsonSerializer.Serialize(response, options)); + Console.ReadKey(); + + // Teardown Library + Library.Terminate(); + } + } +} \ No newline at end of file diff --git a/examples/speak/file/hello-world/Program.cs b/examples/speak/file/hello-world/Program.cs index d21f999c..857c23e1 100644 --- a/examples/speak/file/hello-world/Program.cs +++ b/examples/speak/file/hello-world/Program.cs @@ -20,6 +20,12 @@ static async Task Main(string[] args) // OR very chatty logging //Library.Initialize(LogLevel.Debug); // LogLevel.Default, LogLevel.Debug, LogLevel.Verbose + // JSON options + JsonSerializerOptions options = new(JsonSerializerDefaults.Web) + { + WriteIndented = true + }; + // Set "DEEPGRAM_API_KEY" environment variable to your Deepgram API Key var deepgramClient = new SpeakClient(); @@ -32,7 +38,7 @@ static async Task Main(string[] args) }); //Console.WriteLine(response); - Console.WriteLine(JsonSerializer.Serialize(response)); + Console.WriteLine(JsonSerializer.Serialize(response, options)); Console.ReadKey(); // Teardown Library diff --git a/examples/speak/file/woodchuck/Program.cs b/examples/speak/file/woodchuck/Program.cs index 0297caf2..465906f1 100644 --- a/examples/speak/file/woodchuck/Program.cs +++ b/examples/speak/file/woodchuck/Program.cs @@ -17,6 +17,12 @@ static async Task Main(string[] args) // Normal logging is "Info" level Library.Initialize(); + // JSON options + JsonSerializerOptions options = new(JsonSerializerDefaults.Web) + { + WriteIndented = true + }; + // Set "DEEPGRAM_API_KEY" environment variable to your Deepgram API Key var deepgramClient = new SpeakClient(); @@ -29,7 +35,7 @@ static async Task Main(string[] args) }); //Console.WriteLine(response); - Console.WriteLine(JsonSerializer.Serialize(response)); + Console.WriteLine(JsonSerializer.Serialize(response, options)); Console.ReadKey(); // Teardown Library diff --git a/examples/streaming/factory_example/Factory.csproj b/examples/streaming/factory_example/Factory.csproj new file mode 100644 index 00000000..91d69f95 --- /dev/null +++ b/examples/streaming/factory_example/Factory.csproj @@ -0,0 +1,19 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + + + + + + diff --git a/examples/streaming/factory_example/Program.cs b/examples/streaming/factory_example/Program.cs new file mode 100644 index 00000000..c8831256 --- /dev/null +++ b/examples/streaming/factory_example/Program.cs @@ -0,0 +1,103 @@ +// 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 System.Text.Json; + +using Deepgram.Models.Authenticate.v1; +using Deepgram.Models.Live.v1; +using Deepgram.Logger; +using Deepgram.Microphone; +using System.Threading; + +namespace SampleApp +{ + class Program + { + static async Task Main(string[] args) + { + // Initialize Library with default logging + // Normal logging is "Info" level + Deepgram.Library.Initialize(); + // OR very chatty logging + //Deepgram.Library.Initialize(LogLevel.Debug); // LogLevel.Default, LogLevel.Debug, LogLevel.Verbose + Deepgram.Microphone.Library.Initialize(); + + Console.WriteLine("\n\nPress any key to stop and exit...\n\n\n"); + + // use the client factory with a API Key set with the "DEEPGRAM_API_KEY" environment variable + var liveClient = ClientFactory.CreateLiveClient(); + + // Subscribe to the EventResponseReceived event + liveClient.Subscribe(new EventHandler((sender, e) => + { + Console.WriteLine($"\n\n----> {e.Type} received"); + })); + liveClient.Subscribe(new EventHandler((sender, e) => + { + Console.WriteLine($"----> {e.Type} received"); + })); + liveClient.Subscribe(new EventHandler((sender, e) => + { + if (e.Channel.Alternatives[0].Transcript.Trim() == "") + { + return; + } + + // Console.WriteLine("Transcription received: " + JsonSerializer.Serialize(e.Transcription)); + Console.WriteLine($"----> Speaker: {e.Channel.Alternatives[0].Transcript}"); + })); + liveClient.Subscribe(new EventHandler((sender, e) => + { + Console.WriteLine($"----> {e.Type} received"); + })); + liveClient.Subscribe(new EventHandler((sender, e) => + { + Console.WriteLine($"----> {e.Type} received"); + })); + liveClient.Subscribe(new EventHandler((sender, e) => + { + Console.WriteLine($"----> {e.Type} received"); + })); + liveClient.Subscribe(new EventHandler((sender, e) => + { + Console.WriteLine($"----> {e.Type} received"); + })); + liveClient.Subscribe(new EventHandler((sender, e) => + { + Console.WriteLine($"----> { e.Type} received. Error: {e.Message}"); + })); + + // Start the connection + var liveSchema = new LiveSchema() + { + Model = "nova-2", + Encoding = "linear16", + SampleRate = 16000, + Punctuate = true, + SmartFormat = true, + InterimResults = true, + UtteranceEnd = "1000", + VadEvents = true, + }; + await liveClient.Connect(liveSchema); + + // Microphone streaming + var microphone = new Microphone(liveClient.Send); + microphone.Start(); + + // Wait for the user to press a key + Console.ReadKey(); + + // Stop the microphone + microphone.Stop(); + + // Stop the connection + await liveClient.Stop(); + + // Terminate Libraries + Deepgram.Microphone.Library.Terminate(); + Deepgram.Library.Terminate(); + } + } +} diff --git a/examples/streaming/file/Program.cs b/examples/streaming/file/Program.cs index 73a06415..0540a75f 100644 --- a/examples/streaming/file/Program.cs +++ b/examples/streaming/file/Program.cs @@ -51,9 +51,6 @@ static async Task Main(string[] args) // Stop the connection await liveClient.Stop(); - // Dispose the client - liveClient.Dispose(); - // Teardown Library Library.Terminate(); } diff --git a/examples/streaming/http/Program.cs b/examples/streaming/http/Program.cs index 68df2e29..1fc73b1e 100644 --- a/examples/streaming/http/Program.cs +++ b/examples/streaming/http/Program.cs @@ -65,9 +65,6 @@ static async Task Main(string[] args) // Stop the connection await liveClient.Stop(); - // Dispose the client - liveClient.Dispose(); - // Teardown Library Library.Terminate(); } diff --git a/examples/streaming/microphone/Program.cs b/examples/streaming/microphone/Program.cs index e0632dc2..fbc377b6 100644 --- a/examples/streaming/microphone/Program.cs +++ b/examples/streaming/microphone/Program.cs @@ -98,9 +98,6 @@ static async Task Main(string[] args) // Stop the connection await liveClient.Stop(); - // Dispose the client - liveClient.Dispose(); - // Terminate Libraries Deepgram.Microphone.Library.Terminate(); Deepgram.Library.Terminate();