-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5dfe43
commit f66418c
Showing
5 changed files
with
402 additions
and
373 deletions.
There are no files selected for viewing
138 changes: 69 additions & 69 deletions
138
ElevenLabs-DotNet-Tests/Test_Fixture_07_DubbingEndpoint.cs
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 |
---|---|---|
@@ -1,97 +1,97 @@ | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
namespace ElevenLabs.Tests; | ||
|
||
using ElevenLabs.Dubbing; | ||
using NUnit.Framework; | ||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
|
||
internal class Test_Fixture_07_DubbingEndpoint : AbstractTestFixture | ||
namespace ElevenLabs.Tests | ||
{ | ||
[Test] | ||
public async Task Test_01_Dubbing_File() | ||
internal class Test_Fixture_07_DubbingEndpoint : AbstractTestFixture | ||
{ | ||
Assert.NotNull(ElevenLabsClient.DubbingEndpoint); | ||
|
||
(string FilePath, string MediaType) audio = (Path.GetFullPath("../../../Assets/test_sample_01.ogg"), "audio/mpeg"); | ||
DubbingRequest request = new() | ||
[Test] | ||
public async Task Test_01_Dubbing_File() | ||
{ | ||
File = audio, | ||
SourceLanguage = "en", | ||
TargetLanguage = "es", | ||
NumSpeakers = 1, | ||
Watermark = false, | ||
}; | ||
Assert.NotNull(ElevenLabsClient.DubbingEndpoint); | ||
var filePath = Path.GetFullPath("../../../Assets/test_sample_01.ogg"); | ||
var request = new DubbingRequest | ||
{ | ||
FilePath = filePath, | ||
MediaType = "audio/mpeg", | ||
SourceLanguage = "en", | ||
TargetLanguage = "es", | ||
NumSpeakers = 1, | ||
Watermark = false, | ||
}; | ||
|
||
DubbingResponse response = await ElevenLabsClient.DubbingEndpoint.StartDubbingAsync(request); | ||
Assert.IsFalse(string.IsNullOrEmpty(response.DubbingId)); | ||
Assert.IsTrue(response.ExpectedDurationSeconds > 0); | ||
Console.WriteLine($"Expected Duration: {response.ExpectedDurationSeconds:0.00} seconds"); | ||
var response = await ElevenLabsClient.DubbingEndpoint.StartDubbingAsync(request); | ||
Assert.IsFalse(string.IsNullOrEmpty(response.DubbingId)); | ||
Assert.IsTrue(response.ExpectedDurationSeconds > 0); | ||
Console.WriteLine($"Expected Duration: {response.ExpectedDurationSeconds:0.00} seconds"); | ||
Assert.IsTrue(await ElevenLabsClient.DubbingEndpoint.WaitForDubbingCompletionAsync(response.DubbingId, progress: new Progress<string>(Console.WriteLine))); | ||
|
||
Assert.IsTrue(await ElevenLabsClient.DubbingEndpoint.WaitForDubbingCompletionAsync(response.DubbingId, progress: new Progress<string>(msg => Console.WriteLine(msg)))); | ||
var srcFile = new FileInfo(filePath); | ||
var dubbedPath = new FileInfo($"{srcFile.FullName}.dubbed.{request.TargetLanguage}{srcFile.Extension}"); | ||
{ | ||
await using var fs = File.Open(dubbedPath.FullName, FileMode.Create); | ||
await foreach (var chunk in ElevenLabsClient.DubbingEndpoint.GetDubbedFileAsync(response.DubbingId, request.TargetLanguage)) | ||
{ | ||
await fs.WriteAsync(chunk); | ||
} | ||
} | ||
Assert.IsTrue(dubbedPath.Exists); | ||
Assert.IsTrue(dubbedPath.Length > 0); | ||
|
||
FileInfo srcFile = new(audio.FilePath); | ||
FileInfo dubbedPath = new($"{srcFile.FullName}.dubbed.{request.TargetLanguage}{srcFile.Extension}"); | ||
{ | ||
await using FileStream fs = File.Open(dubbedPath.FullName, FileMode.Create); | ||
await foreach (byte[] chunk in ElevenLabsClient.DubbingEndpoint.GetDubbedFileAsync(response.DubbingId, request.TargetLanguage)) | ||
var transcriptPath = new FileInfo($"{srcFile.FullName}.dubbed.{request.TargetLanguage}.srt"); | ||
{ | ||
await fs.WriteAsync(chunk); | ||
var transcriptFile = await ElevenLabsClient.DubbingEndpoint.GetTranscriptForDubAsync(response.DubbingId, request.TargetLanguage, "srt"); | ||
await File.WriteAllTextAsync(transcriptPath.FullName, transcriptFile); | ||
} | ||
Assert.IsTrue(transcriptPath.Exists); | ||
Assert.IsTrue(transcriptPath.Length > 0); | ||
} | ||
Assert.IsTrue(dubbedPath.Exists); | ||
Assert.IsTrue(dubbedPath.Length > 0); | ||
|
||
FileInfo transcriptPath = new($"{srcFile.FullName}.dubbed.{request.TargetLanguage}.srt"); | ||
[Test] | ||
public async Task Test_02_Dubbing_Url() | ||
{ | ||
string transcriptFile = await ElevenLabsClient.DubbingEndpoint.GetTranscriptForDubAsync(response.DubbingId, request.TargetLanguage, "srt"); | ||
await File.WriteAllTextAsync(transcriptPath.FullName, transcriptFile); | ||
} | ||
Assert.IsTrue(transcriptPath.Exists); | ||
Assert.IsTrue(transcriptPath.Length > 0); | ||
} | ||
|
||
[Test] | ||
public async Task Test_02_Dubbing_Url() | ||
{ | ||
Assert.NotNull(ElevenLabsClient.DubbingEndpoint); | ||
Assert.NotNull(ElevenLabsClient.DubbingEndpoint); | ||
|
||
Uri uri = new("https://youtu.be/Zo5-rhYOlNk"); | ||
DubbingRequest request = new() | ||
{ | ||
SourceUrl = uri.AbsoluteUri, | ||
SourceLanguage = "en", | ||
TargetLanguage = "ja", | ||
NumSpeakers = 1, | ||
Watermark = true, | ||
}; | ||
|
||
DubbingResponse response = await ElevenLabsClient.DubbingEndpoint.StartDubbingAsync(request); | ||
Assert.IsFalse(string.IsNullOrEmpty(response.DubbingId)); | ||
Assert.IsTrue(response.ExpectedDurationSeconds > 0); | ||
Console.WriteLine($"Expected Duration: {response.ExpectedDurationSeconds:0.00} seconds"); | ||
var uri = new Uri("https://youtu.be/Zo5-rhYOlNk"); | ||
var request = new DubbingRequest | ||
{ | ||
SourceUrl = uri.AbsoluteUri, | ||
SourceLanguage = "en", | ||
TargetLanguage = "ja", | ||
NumSpeakers = 1, | ||
Watermark = true, | ||
}; | ||
|
||
Assert.IsTrue(await ElevenLabsClient.DubbingEndpoint.WaitForDubbingCompletionAsync(response.DubbingId, progress: new Progress<string>(msg => Console.WriteLine(msg)))); | ||
var response = await ElevenLabsClient.DubbingEndpoint.StartDubbingAsync(request); | ||
Assert.IsFalse(string.IsNullOrEmpty(response.DubbingId)); | ||
Assert.IsTrue(response.ExpectedDurationSeconds > 0); | ||
Console.WriteLine($"Expected Duration: {response.ExpectedDurationSeconds:0.00} seconds"); | ||
Assert.IsTrue(await ElevenLabsClient.DubbingEndpoint.WaitForDubbingCompletionAsync(response.DubbingId, progress: new Progress<string>(Console.WriteLine))); | ||
|
||
string assetsDir = Path.GetFullPath("../../../Assets"); | ||
FileInfo dubbedPath = new(Path.Combine(assetsDir, $"online.dubbed.{request.TargetLanguage}.mp4")); | ||
{ | ||
await using FileStream fs = File.Open(dubbedPath.FullName, FileMode.Create); | ||
await foreach (byte[] chunk in ElevenLabsClient.DubbingEndpoint.GetDubbedFileAsync(response.DubbingId, request.TargetLanguage)) | ||
var assetsDir = Path.GetFullPath("../../../Assets"); | ||
var dubbedPath = new FileInfo(Path.Combine(assetsDir, $"online.dubbed.{request.TargetLanguage}.mp4")); | ||
{ | ||
await fs.WriteAsync(chunk); | ||
await using var fs = File.Open(dubbedPath.FullName, FileMode.Create); | ||
await foreach (var chunk in ElevenLabsClient.DubbingEndpoint.GetDubbedFileAsync(response.DubbingId, request.TargetLanguage)) | ||
{ | ||
await fs.WriteAsync(chunk); | ||
} | ||
} | ||
} | ||
Assert.IsTrue(dubbedPath.Exists); | ||
Assert.IsTrue(dubbedPath.Length > 0); | ||
Assert.IsTrue(dubbedPath.Exists); | ||
Assert.IsTrue(dubbedPath.Length > 0); | ||
|
||
FileInfo transcriptPath = new(Path.Combine(assetsDir, $"online.dubbed.{request.TargetLanguage}.srt")); | ||
{ | ||
string transcriptFile = await ElevenLabsClient.DubbingEndpoint.GetTranscriptForDubAsync(response.DubbingId, request.TargetLanguage, "srt"); | ||
await File.WriteAllTextAsync(transcriptPath.FullName, transcriptFile); | ||
var transcriptPath = new FileInfo(Path.Combine(assetsDir, $"online.dubbed.{request.TargetLanguage}.srt")); | ||
{ | ||
var transcriptFile = await ElevenLabsClient.DubbingEndpoint.GetTranscriptForDubAsync(response.DubbingId, request.TargetLanguage, "srt"); | ||
await File.WriteAllTextAsync(transcriptPath.FullName, transcriptFile); | ||
} | ||
Assert.IsTrue(transcriptPath.Exists); | ||
Assert.IsTrue(transcriptPath.Length > 0); | ||
} | ||
Assert.IsTrue(transcriptPath.Exists); | ||
Assert.IsTrue(transcriptPath.Length > 0); | ||
} | ||
} |
Oops, something went wrong.