-
-
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.
- Added VoiceGenerationEndpoint - Added unit tests for voice design and instant voice cloning - Updated docs
- Loading branch information
1 parent
e875f62
commit 4d4204f
Showing
10 changed files
with
149 additions
and
39 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
46 changes: 46 additions & 0 deletions
46
ElevenLabs-DotNet-Tests/Test_Fixture_05_VoiceGeneration.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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
||
using ElevenLabs.VoiceGeneration; | ||
using NUnit.Framework; | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
|
||
namespace ElevenLabs.Voice.Tests | ||
{ | ||
internal class Test_Fixture_05_VoiceGeneration | ||
{ | ||
[Test] | ||
public async Task Test_01_GetVoiceGenerationOptions() | ||
{ | ||
var api = new ElevenLabsClient(ElevenLabsAuthentication.LoadFromEnv()); | ||
Assert.NotNull(api.VoiceGenerationEndpoint); | ||
var options = await api.VoiceGenerationEndpoint.GetVoiceGenerationOptionsAsync(); | ||
Assert.NotNull(options); | ||
Console.WriteLine(JsonSerializer.Serialize(options)); | ||
} | ||
|
||
[Test] | ||
public async Task Test_02_GenerateVoice() | ||
{ | ||
var api = new ElevenLabsClient(ElevenLabsAuthentication.LoadFromEnv()); | ||
Assert.NotNull(api.VoiceGenerationEndpoint); | ||
var options = await api.VoiceGenerationEndpoint.GetVoiceGenerationOptionsAsync(); | ||
var generateRequest = new GeneratedVoiceRequest("First we thought the PC was a calculator. Then we found out how to turn numbers into letters and we thought it was a typewriter.", options.Genders.FirstOrDefault(), options.Accents.FirstOrDefault(), options.Ages.FirstOrDefault()); | ||
var (generatedVoiceId, audioFilePath) = await api.VoiceGenerationEndpoint.GenerateVoiceAsync(generateRequest); | ||
Console.WriteLine(generatedVoiceId); | ||
Console.WriteLine(audioFilePath); | ||
var createVoiceRequest = new CreateVoiceRequest("Test Voice Lab Create Voice", generatedVoiceId); | ||
File.Delete(audioFilePath); | ||
Assert.NotNull(createVoiceRequest); | ||
var result = await api.VoiceGenerationEndpoint.CreateVoiceAsync(createVoiceRequest); | ||
Assert.NotNull(result); | ||
Console.WriteLine(result.Id); | ||
var deleteResult = await api.VoicesEndpoint.DeleteVoiceAsync(result.Id); | ||
Assert.NotNull(deleteResult); | ||
Assert.IsTrue(deleteResult); | ||
} | ||
} | ||
} |
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
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
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
57 changes: 47 additions & 10 deletions
57
ElevenLabs-DotNet/VoiceGeneration/GeneratedVoiceRequest.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,29 +1,66 @@ | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
||
using System; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace ElevenLabs.VoiceGeneration | ||
{ | ||
public sealed class GeneratedVoiceRequest | ||
{ | ||
[JsonInclude] | ||
/// <summary> | ||
/// Voice Generation Request. | ||
/// Use <see cref="VoiceGenerationEndpoint.GetVoiceGenerationOptionsAsync"/> to get a full list of options. | ||
/// </summary> | ||
/// <param name="text">Sample text to return for voice generation. Must be between 100 and 1000 characters.</param> | ||
/// <param name="gender">The gender of the voice to generate.</param> | ||
/// <param name="accent">The accent of the voice to generate.</param> | ||
/// <param name="age">The age of the voice to generate.</param> | ||
/// <param name="accentStrength">Optional, accept strength, between 0.3 - 2.</param> | ||
public GeneratedVoiceRequest(string text, Gender gender, Accent accent, Age age, double accentStrength = 1) | ||
{ | ||
switch (text.Length) | ||
{ | ||
case < 100: | ||
throw new ArgumentOutOfRangeException(nameof(text), $"{nameof(text)} must be longer than 100 characters."); | ||
case > 1000: | ||
throw new ArgumentOutOfRangeException(nameof(text), $"{nameof(text)} cannot be longer than 1000 characters."); | ||
default: | ||
if (string.IsNullOrWhiteSpace(text)) | ||
{ | ||
throw new ArgumentNullException(nameof(text)); | ||
} | ||
|
||
break; | ||
} | ||
|
||
Text = text; | ||
Gender = gender.Code; | ||
Accent = accent.Code; | ||
Age = age.Code; | ||
|
||
accentStrength = accentStrength switch | ||
{ | ||
< 0.3f => 0.3f, | ||
> 2f => 2f, | ||
_ => accentStrength | ||
}; | ||
|
||
AccentStrength = accentStrength; | ||
} | ||
|
||
[JsonPropertyName("text")] | ||
public string Text { get; private set; } | ||
public string Text { get; } | ||
|
||
[JsonInclude] | ||
[JsonPropertyName("gender")] | ||
public string Gender { get; private set; } | ||
public string Gender { get; } | ||
|
||
[JsonInclude] | ||
[JsonPropertyName("accent")] | ||
public string Accent { get; private set; } | ||
public string Accent { get; } | ||
|
||
[JsonInclude] | ||
[JsonPropertyName("age")] | ||
public string Age { get; private set; } | ||
public string Age { get; } | ||
|
||
[JsonInclude] | ||
[JsonPropertyName("accent_strength")] | ||
public int AccentStrength { get; private set; } | ||
public double AccentStrength { get; } | ||
} | ||
} |
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