From 6a2fdf90fcb81cde817cd98564202eec436e0671 Mon Sep 17 00:00:00 2001 From: Stephen Hodgson Date: Mon, 2 Sep 2024 18:54:38 -0400 Subject: [PATCH] ElevenLabs-DotNet 3.0.2 - Cleanup and polish for Dubbing API --- ElevenLabs-DotNet/Dubbing/DubbingEndpoint.cs | 45 +++++++++---------- .../Dubbing/DubbingProjectMetadata.cs | 2 +- ElevenLabs-DotNet/ElevenLabs-DotNet.csproj | 4 +- .../SoundGeneration/SoundGenerationRequest.cs | 2 +- 4 files changed, 25 insertions(+), 28 deletions(-) diff --git a/ElevenLabs-DotNet/Dubbing/DubbingEndpoint.cs b/ElevenLabs-DotNet/Dubbing/DubbingEndpoint.cs index c9d0e98..42148ff 100644 --- a/ElevenLabs-DotNet/Dubbing/DubbingEndpoint.cs +++ b/ElevenLabs-DotNet/Dubbing/DubbingEndpoint.cs @@ -18,20 +18,17 @@ namespace ElevenLabs.Dubbing /// public sealed class DubbingEndpoint(ElevenLabsClient client) : ElevenLabsBaseEndPoint(client) { - private const string DubbingId = "dubbing_id"; - private const string ExpectedDurationSecs = "expected_duration_sec"; - protected override string Root => "dubbing"; /// /// Dubs provided audio or video file into given language. /// /// The containing dubbing configuration and files. - /// + /// progress callback. /// Optional, . - /// - /// - /// . + /// Optional, number of retry attempts when polling. + /// Optional, between making requests. + /// . public async Task DubAsync(DubbingRequest request, int? maxRetries = null, TimeSpan? pollingInterval = null, IProgress progress = null, CancellationToken cancellationToken = default) { ArgumentNullException.ThrowIfNull(request); @@ -39,9 +36,12 @@ public async Task DubAsync(DubbingRequest request, int? try { - foreach (var (fileName, mediaType, stream) in request.Files) + if (request.Files != null) { - await payload.AppendFileToFormAsync("file", stream, fileName, new(mediaType), cancellationToken); + foreach (var (fileName, mediaType, stream) in request.Files) + { + await payload.AppendFileToFormAsync("file", stream, fileName, new(mediaType), cancellationToken); + } } if (!string.IsNullOrEmpty(request.ProjectName)) @@ -97,8 +97,7 @@ public async Task DubAsync(DubbingRequest request, int? using var response = await client.Client.PostAsync(GetUrl(), payload, cancellationToken).ConfigureAwait(false); var responseBody = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false); var dubResponse = JsonSerializer.Deserialize(responseBody); - var metadata = await WaitForDubbingCompletionAsync(dubResponse, maxRetries ?? 60, pollingInterval ?? TimeSpan.FromSeconds(dubResponse.ExpectedDurationSeconds), pollingInterval == null, progress, cancellationToken); - return metadata; + return await WaitForDubbingCompletionAsync(dubResponse, maxRetries ?? 60, pollingInterval ?? TimeSpan.FromSeconds(dubResponse.ExpectedDurationSeconds), pollingInterval == null, progress, cancellationToken); } private async Task WaitForDubbingCompletionAsync(DubbingResponse dubbingResponse, int maxRetries, TimeSpan pollingInterval, bool adjustInterval, IProgress progress = null, CancellationToken cancellationToken = default) @@ -122,14 +121,14 @@ private async Task WaitForDubbingCompletionAsync(Dubbing if (metadata.Status.Equals("dubbing", StringComparison.Ordinal)) { - if (EnableDebug) + if (adjustInterval && pollingInterval.TotalSeconds > 0.5f) { - Console.WriteLine($"Dubbing for {dubbingResponse.DubbingId} in progress... Will check status again in {pollingInterval.TotalSeconds} seconds."); + pollingInterval = TimeSpan.FromSeconds(dubbingResponse.ExpectedDurationSeconds / Math.Pow(2, i)); } - if (adjustInterval) + if (EnableDebug) { - pollingInterval = TimeSpan.FromSeconds(dubbingResponse.ExpectedDurationSeconds / Math.Pow(2, i)); + Console.WriteLine($"Dubbing for {dubbingResponse.DubbingId} in progress... Will check status again in {pollingInterval.TotalSeconds} seconds."); } await Task.Delay(pollingInterval, cancellationToken).ConfigureAwait(false); @@ -146,7 +145,7 @@ private async Task WaitForDubbingCompletionAsync(Dubbing /// /// Returns metadata about a dubbing project, including whether it’s still in progress or not. /// - /// + /// Dubbing project id. /// Optional, . /// . public async Task GetDubbingProjectMetadataAsync(string dubbingId, CancellationToken cancellationToken = default) @@ -159,17 +158,13 @@ public async Task GetDubbingProjectMetadataAsync(string /// /// Returns transcript for the dub in the specified format (SRT or WebVTT). /// - /// The ID of the dubbing project. + /// Dubbing project id. /// The language code of the transcript. - /// Optional. The format type of the transcript file, either 'srt' or 'webvtt'. + /// Optional. The format type of the transcript file, either or . /// Optional, . /// - /// A task representing the asynchronous operation. The task completes with the transcript content - /// as a string in the specified format. + /// A string containing the transcript content in the specified format. /// - /// - /// If is not specified, the method retrieves the transcript in its default format. - /// public async Task GetTranscriptForDubAsync(string dubbingId, string languageCode, DubbingFormat formatType = DubbingFormat.Srt, CancellationToken cancellationToken = default) { var @params = new Dictionary { { "format_type", formatType.ToString().ToLower() } }; @@ -180,7 +175,7 @@ public async Task GetTranscriptForDubAsync(string dubbingId, string lang /// /// Returns dubbed file as a streamed file. /// - /// The ID of the dubbing project. + /// Dubbing project id. /// The language code of the dubbed content. /// The size of the buffer used to read data from the response stream. Default is 8192 bytes. /// Optional, . @@ -211,7 +206,7 @@ public async IAsyncEnumerable GetDubbedFileAsync(string dubbingId, strin /// /// Deletes a dubbing project. /// - /// The ID of the dubbing project. + /// Dubbing project id. /// Optional, . public async Task DeleteDubbingProjectAsync(string dubbingId, CancellationToken cancellationToken = default) { diff --git a/ElevenLabs-DotNet/Dubbing/DubbingProjectMetadata.cs b/ElevenLabs-DotNet/Dubbing/DubbingProjectMetadata.cs index 556bc77..478845c 100644 --- a/ElevenLabs-DotNet/Dubbing/DubbingProjectMetadata.cs +++ b/ElevenLabs-DotNet/Dubbing/DubbingProjectMetadata.cs @@ -22,7 +22,7 @@ public sealed class DubbingProjectMetadata [JsonInclude] [JsonPropertyName("target_languages")] - public List TargetLanguages { get; private set; } + public IReadOnlyList TargetLanguages { get; private set; } [JsonInclude] [JsonPropertyName("error")] diff --git a/ElevenLabs-DotNet/ElevenLabs-DotNet.csproj b/ElevenLabs-DotNet/ElevenLabs-DotNet.csproj index 55f3b75..cdb8f2e 100644 --- a/ElevenLabs-DotNet/ElevenLabs-DotNet.csproj +++ b/ElevenLabs-DotNet/ElevenLabs-DotNet.csproj @@ -25,8 +25,10 @@ All copyrights, trademarks, logos, and assets are the property of their respecti false true true - 3.0.1 + 3.0.2 +Version 3.0.2 +- Cleanup and polish for Dubbing API Version 3.0.1 - Updated Models Version 3.0.0 diff --git a/ElevenLabs-DotNet/SoundGeneration/SoundGenerationRequest.cs b/ElevenLabs-DotNet/SoundGeneration/SoundGenerationRequest.cs index 9bf41ec..1f6ea83 100644 --- a/ElevenLabs-DotNet/SoundGeneration/SoundGenerationRequest.cs +++ b/ElevenLabs-DotNet/SoundGeneration/SoundGenerationRequest.cs @@ -8,7 +8,7 @@ namespace ElevenLabs.SoundGeneration public sealed class SoundGenerationRequest { /// - /// + /// Constructor. /// /// /// The text that will get converted into a sound effect.