Skip to content

Commit c85aa76

Browse files
ElevenLabs-DotNet 3.6.0 (#91)
- Added support for versioned endpoints - Added /v2/voices endpoint with GetVoicesAsync ## ElevenLabs-DotNet-Proxy 3.6.0 - Added support for versioned endpoints --- This PR allows to query the v2 endpoint of voices using a `VoiceQuery` parameter See https://github.com/RageAgainstThePixel/ElevenLabs-DotNet/pull/91/files#diff-91e6144e87e5e218811627cb868cb955c56f819b1066c376634fa41537ad7afd for parameters to filter by It also allows to paginate through the results https://github.com/RageAgainstThePixel/ElevenLabs-DotNet/pull/91/files#diff-50ee419400984e7f9c54ed0ca463f9fcca03cb21f371002c2300a33de663e01cR228 --------- Co-authored-by: Stephen Hodgson <[email protected]>
1 parent ac5b7cc commit c85aa76

17 files changed

+432
-33
lines changed

ElevenLabs-DotNet-Proxy/ElevenLabs-DotNet-Proxy.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
2121
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
2222
<SignAssembly>false</SignAssembly>
23-
<Version>3.5.2</Version>
23+
<Version>3.6.0</Version>
2424
<PackageReleaseNotes>
25+
Version 3.6.0
26+
- Added support for versioned endpoints
2527
Version 3.5.2
2628
- Forward the content and headers from the backend service to the client, preserving the original response details.
2729
Version 3.5.1

ElevenLabs-DotNet-Proxy/Proxy/EndpointRouteBuilder.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ public static class EndpointRouteBuilder
5353
/// <param name="routePrefix">Optional, custom route prefix. i.e. '/elevenlabs'.</param>
5454
public static void MapElevenLabsEndpoints(this IEndpointRouteBuilder endpoints, ElevenLabsClient client, IAuthenticationFilter authenticationFilter, string routePrefix = "")
5555
{
56-
endpoints.Map($"{routePrefix}{client.Settings.BaseRequest}{{**endpoint}}", HandleRequest);
56+
endpoints.Map($"{routePrefix}/{{version}}/{{**endpoint}}", HandleRequest);
5757
return;
5858

59-
async Task HandleRequest(HttpContext httpContext, string endpoint)
59+
async Task HandleRequest(HttpContext httpContext, string version, string endpoint)
6060
{
6161
try
6262
{
@@ -72,6 +72,7 @@ async Task HandleRequest(HttpContext httpContext, string endpoint)
7272

7373
var uri = new Uri(string.Format(
7474
client.Settings.BaseRequestUrlFormat,
75+
version,
7576
QueryHelpers.AddQueryString(endpoint, modifiedQuery)
7677
));
7778

ElevenLabs-DotNet-Tests/TestFixture_00_Authentication.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ public void Test_09_CustomDomainConfigurationSettings()
112112
var auth = new ElevenLabsAuthentication("customIssuedToken");
113113
var settings = new ElevenLabsClientSettings(domain: "api.your-custom-domain.com");
114114
var api = new ElevenLabsClient(auth, settings);
115-
Console.WriteLine(api.Settings.BaseRequest);
116115
Console.WriteLine(api.Settings.BaseRequestUrlFormat);
117116
}
118117

ElevenLabs-DotNet-Tests/TestFixture_03_VoicesEndpoint.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,5 +211,42 @@ public async Task Test_11_DeleteVoice()
211211
Assert.IsTrue(result);
212212
}
213213
}
214+
215+
[Test]
216+
public async Task Test_12_01_IterateDefaultVoices()
217+
{
218+
Assert.NotNull(ElevenLabsClient.VoicesV2Endpoint);
219+
var voices = new List<Voice>();
220+
var query = new VoiceQuery(voiceType: VoiceTypes.Default, pageSize: 10);
221+
int? previousTotalCount = null;
222+
223+
do
224+
{
225+
var page = await ElevenLabsClient.VoicesV2Endpoint.GetVoicesAsync(query);
226+
227+
if (page.HasMore)
228+
{
229+
Assert.AreEqual(query.PageSize, page.Voices.Count);
230+
}
231+
232+
if (previousTotalCount != null)
233+
{
234+
Assert.AreEqual(previousTotalCount, page.TotalCount);
235+
}
236+
237+
previousTotalCount = page.TotalCount;
238+
voices.AddRange(page.Voices);
239+
query = query.WithNextPageToken(page.NextPageToken);
240+
} while (!string.IsNullOrWhiteSpace(query.NextPageToken));
241+
242+
Assert.NotNull(voices);
243+
Assert.IsNotEmpty(voices);
244+
Assert.AreEqual(previousTotalCount, voices.Count);
245+
246+
foreach (var voice in voices)
247+
{
248+
Console.WriteLine($"{voice.Id} | {voice.Name}");
249+
}
250+
}
214251
}
215252
}

ElevenLabs-DotNet/Authentication/ElevenLabsClientSettings.cs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ public sealed class ElevenLabsClientSettings
88
{
99
internal const string Http = "http://";
1010
internal const string Https = "https://";
11-
internal const string DefaultApiVersion = "v1";
1211
internal const string ElevenLabsDomain = "api.elevenlabs.io";
1312

1413
/// <summary>
@@ -17,17 +16,14 @@ public sealed class ElevenLabsClientSettings
1716
public ElevenLabsClientSettings()
1817
{
1918
Domain = ElevenLabsDomain;
20-
ApiVersion = "v1";
21-
BaseRequest = $"/{ApiVersion}/";
22-
BaseRequestUrlFormat = $"{Https}{Domain}{BaseRequest}{{0}}";
19+
BaseRequestUrlFormat = $"{Https}{Domain}/{{0}}/{{1}}";
2320
}
2421

2522
/// <summary>
2623
/// Creates a new instance of <see cref="ElevenLabsClientSettings"/> for use with ElevenLabs API.
2724
/// </summary>
2825
/// <param name="domain">Base api domain.</param>
29-
/// <param name="apiVersion">The version of the ElevenLabs api you want to use.</param>
30-
public ElevenLabsClientSettings(string domain, string apiVersion = DefaultApiVersion)
26+
public ElevenLabsClientSettings(string domain)
3127
{
3228
if (string.IsNullOrWhiteSpace(domain))
3329
{
@@ -40,11 +36,6 @@ public ElevenLabsClientSettings(string domain, string apiVersion = DefaultApiVer
4036
throw new ArgumentException($"You're attempting to pass a \"resourceName\" parameter to \"{nameof(domain)}\". Please specify \"resourceName:\" for this parameter in constructor.");
4137
}
4238

43-
if (string.IsNullOrWhiteSpace(apiVersion))
44-
{
45-
apiVersion = DefaultApiVersion;
46-
}
47-
4839
var protocol = Https;
4940

5041
if (domain.StartsWith(Http))
@@ -59,18 +50,12 @@ public ElevenLabsClientSettings(string domain, string apiVersion = DefaultApiVer
5950
}
6051

6152
Domain = $"{protocol}{domain}";
62-
ApiVersion = apiVersion;
63-
BaseRequest = $"/{ApiVersion}/";
64-
BaseRequestUrlFormat = $"{Domain}{BaseRequest}{{0}}";
53+
BaseRequestUrlFormat = $"{Domain}/{{0}}/{{1}}";
6554
}
6655

6756
public string Domain { get; }
6857

69-
public string ApiVersion { get; }
70-
71-
public string BaseRequest { get; }
72-
73-
public string BaseRequestUrlFormat { get; }
58+
internal string BaseRequestUrlFormat { get; }
7459

7560
public static ElevenLabsClientSettings Default { get; } = new();
7661
}

ElevenLabs-DotNet/Common/ElevenLabsBaseEndPoint.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ public abstract class ElevenLabsBaseEndPoint
1717
/// </summary>
1818
protected abstract string Root { get; }
1919

20+
protected virtual string ApiVersion => "v1";
21+
2022
/// <summary>
2123
/// Gets the full formatted url for the API endpoint.
2224
/// </summary>
2325
/// <param name="endpoint">The endpoint url.</param>
2426
/// <param name="queryParameters">Optional, parameters to add to the endpoint.</param>
2527
protected string GetUrl(string endpoint = "", Dictionary<string, string> queryParameters = null)
2628
{
27-
var result = string.Format(client.Settings.BaseRequestUrlFormat, $"{Root}{endpoint}");
29+
var result = string.Format(client.Settings.BaseRequestUrlFormat, ApiVersion, $"{Root}{endpoint}");
2830

2931
if (queryParameters is { Count: not 0 })
3032
{

ElevenLabs-DotNet/ElevenLabs-DotNet.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ All copyrights, trademarks, logos, and assets are the property of their respecti
2525
<SignAssembly>false</SignAssembly>
2626
<IncludeSymbols>true</IncludeSymbols>
2727
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
28-
<Version>3.5.1</Version>
28+
<Version>3.6.0</Version>
2929
<PackageReleaseNotes>
30+
Version 3.6.0
31+
- Added support for versioned endpoints
32+
- Added /v2/voices endpoint with GetVoicesAsync
3033
Version 3.5.1
3134
- Fix some proxy support issues.
3235
Version 3.5.0

ElevenLabs-DotNet/ElevenLabsClient.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public ElevenLabsClient(ElevenLabsAuthentication authentication = null, ElevenLa
6464

6565
UserEndpoint = new UserEndpoint(this);
6666
VoicesEndpoint = new VoicesEndpoint(this);
67+
VoicesV2Endpoint = new VoicesV2Endpoint(this);
6768
SharedVoicesEndpoint = new SharedVoicesEndpoint(this);
6869
ModelsEndpoint = new ModelsEndpoint(this);
6970
HistoryEndpoint = new HistoryEndpoint(this);
@@ -134,6 +135,8 @@ private void Dispose(bool disposing)
134135

135136
public VoicesEndpoint VoicesEndpoint { get; }
136137

138+
public VoicesV2Endpoint VoicesV2Endpoint { get; }
139+
137140
public SharedVoicesEndpoint SharedVoicesEndpoint { get; }
138141

139142
public ModelsEndpoint ModelsEndpoint { get; }
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Licensed under the MIT License. See LICENSE in the project root for license information.
2+
3+
using System.Runtime.Serialization;
4+
5+
namespace ElevenLabs.Voices
6+
{
7+
/// <summary>
8+
/// Category of the voice to filter by.
9+
/// </summary>
10+
public enum CategoryTypes
11+
{
12+
/// <summary>
13+
/// Premade voice.
14+
/// </summary>
15+
[EnumMember(Value = "premade")]
16+
Premade,
17+
/// <summary>
18+
/// Cloned voice.
19+
/// </summary>
20+
[EnumMember(Value = "cloned")]
21+
Cloned,
22+
/// <summary>
23+
/// Generated voice.
24+
/// </summary>
25+
[EnumMember(Value = "generated")]
26+
Generated,
27+
/// <summary>
28+
/// Professional voice.
29+
/// </summary>
30+
[EnumMember(Value = "professional")]
31+
Professional
32+
}
33+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Licensed under the MIT License. See LICENSE in the project root for license information.
2+
3+
using System.Runtime.Serialization;
4+
5+
namespace ElevenLabs.Voices
6+
{
7+
/// <summary>
8+
/// State of the voice’s fine-tuning to filter by. Applicable only to professional voices clones.
9+
/// </summary>
10+
public enum FineTuningStateTypes
11+
{
12+
/// <summary>
13+
/// Draft state.
14+
/// </summary>
15+
[EnumMember(Value = "draft")]
16+
Draft,
17+
/// <summary>
18+
/// Not verified state.
19+
/// </summary>
20+
[EnumMember(Value = "not_verified")]
21+
NotVerified,
22+
/// <summary>
23+
/// Not started state.
24+
/// </summary>
25+
[EnumMember(Value = "not_started")]
26+
NotStarted,
27+
/// <summary>
28+
/// Queued state.
29+
/// </summary>
30+
[EnumMember(Value = "queued")]
31+
Queued,
32+
/// <summary>
33+
/// Fine-tuning in progress.
34+
/// </summary>
35+
[EnumMember(Value = "fine_tuning")]
36+
FineTuning,
37+
/// <summary>
38+
/// Fine-tuned state.
39+
/// </summary>
40+
[EnumMember(Value = "fine_tuned")]
41+
FineTuned,
42+
/// <summary>
43+
/// Failed state.
44+
/// </summary>
45+
[EnumMember(Value = "failed")]
46+
Failed,
47+
/// <summary>
48+
/// Delayed state.
49+
/// </summary>
50+
[EnumMember(Value = "delayed")]
51+
Delayed
52+
}
53+
}

0 commit comments

Comments
 (0)