diff --git a/ElevenLabs-DotNet/Dubbing/DubbingEndpoint.cs b/ElevenLabs-DotNet/Dubbing/DubbingEndpoint.cs index efa9738..dcec750 100644 --- a/ElevenLabs-DotNet/Dubbing/DubbingEndpoint.cs +++ b/ElevenLabs-DotNet/Dubbing/DubbingEndpoint.cs @@ -38,9 +38,9 @@ public async Task DubAsync(DubbingRequest request, int? { if (request.Files != null) { - foreach (var (fileName, mediaType, stream) in request.Files) + foreach (var dub in request.Files) { - await payload.AppendFileToFormAsync("file", stream, fileName, new(mediaType), cancellationToken); + await payload.AppendFileToFormAsync("file", dub.Stream, dub.Name, new(dub.MediaType), cancellationToken); } } diff --git a/ElevenLabs-DotNet/Dubbing/DubbingRequest.cs b/ElevenLabs-DotNet/Dubbing/DubbingRequest.cs index 403fedf..057b910 100644 --- a/ElevenLabs-DotNet/Dubbing/DubbingRequest.cs +++ b/ElevenLabs-DotNet/Dubbing/DubbingRequest.cs @@ -57,7 +57,7 @@ public DubbingRequest( } public DubbingRequest( - List<(string, string, Stream)> files, + List files, string targetLanguage, string sourceLanguage = null, int? numberOfSpeakers = null, @@ -75,7 +75,7 @@ public DubbingRequest( private DubbingRequest( string targetLanguage, Uri sourceUrl = null, - List<(string, string, Stream)> files = null, + List files = null, IEnumerable filePaths = null, string sourceLanguage = null, int? numberOfSpeakers = null, @@ -130,7 +130,7 @@ private DubbingRequest( ".webm" => "video/webm", _ => "application/octet-stream" }; - files.Add((fileInfo.Name, mediaType, stream)); + files.Add(new(stream, fileInfo.Name, mediaType)); } } @@ -152,7 +152,7 @@ private DubbingRequest( /// /// Files to dub. /// - public IReadOnlyList<(string, string, Stream)> Files { get; } + public IReadOnlyList Files { get; } /// /// URL of the source video/audio file. @@ -221,12 +221,12 @@ private void Dispose(bool disposing) if (disposing) { if (Files == null) { return; } - foreach (var (_, _, stream) in Files) + + foreach (var dub in Files) { try { - stream?.Close(); - stream?.Dispose(); + dub.Dispose(); } catch (Exception e) { diff --git a/ElevenLabs-DotNet/Dubbing/DubbingStream.cs b/ElevenLabs-DotNet/Dubbing/DubbingStream.cs new file mode 100644 index 0000000..ddbbd63 --- /dev/null +++ b/ElevenLabs-DotNet/Dubbing/DubbingStream.cs @@ -0,0 +1,64 @@ +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using System; +using System.IO; + +namespace ElevenLabs.Dubbing +{ + public sealed class DubbingStream : IDisposable + { + public DubbingStream(Stream stream, string name, string mediaType) + { + Stream = stream ?? throw new ArgumentNullException(nameof(stream)); + + if (Stream.Length == 0) + { + throw new ArgumentException("Stream cannot be empty."); + } + + if (!Stream.CanRead) + { + throw new ArgumentException("Stream must be readable."); + } + + Name = name ?? throw new ArgumentNullException(nameof(name)); + + if (string.IsNullOrWhiteSpace(Name)) + { + throw new ArgumentException("Name cannot be empty."); + } + + MediaType = mediaType ?? throw new ArgumentNullException(nameof(mediaType)); + + if (string.IsNullOrWhiteSpace(MediaType)) + { + throw new ArgumentException("Media type cannot be empty."); + } + + if (MediaType.Contains("/")) + { + var parts = MediaType.Split('/'); + + if (parts.Length != 2 || string.IsNullOrWhiteSpace(parts[0]) || string.IsNullOrWhiteSpace(parts[1])) + { + throw new ArgumentException("Invalid media type."); + } + } + else + { + throw new ArgumentException("Invalid media type."); + } + } + + public Stream Stream { get; } + + public string Name { get; } + + public string MediaType { get; } + + public void Dispose() + { + Stream?.Dispose(); + } + } +} diff --git a/ElevenLabs-DotNet/ElevenLabs-DotNet.csproj b/ElevenLabs-DotNet/ElevenLabs-DotNet.csproj index 0bffdfb..9321319 100644 --- a/ElevenLabs-DotNet/ElevenLabs-DotNet.csproj +++ b/ElevenLabs-DotNet/ElevenLabs-DotNet.csproj @@ -29,6 +29,7 @@ All copyrights, trademarks, logos, and assets are the property of their respecti Version 3.4.2 - Added flash models +- Added stream input support to dubbing endpoint - Fixed http/https protocol in client settings Version 3.4.1 - Removed text length check in TextToSpeechRequest