Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using System.Collections.Generic;
using Utilities.WebRequestRest.Interfaces;

namespace ElevenLabs
{
public sealed class ElevenLabsSettingsInfo : ISettingsInfo
{
internal const string WS = "ws://";
internal const string WSS = "wss://";
internal const string Http = "http://";
internal const string Https = "https://";
internal const string ElevenLabsDomain = "api.elevenlabs.io";
Expand All @@ -21,6 +24,7 @@ public ElevenLabsSettingsInfo()
ApiVersion = DefaultApiVersion;
BaseRequest = $"/{ApiVersion}/";
BaseRequestUrlFormat = $"{Https}{Domain}{BaseRequest}{{0}}";
BaseWebSocketUrlFormat = $"{WSS}{Domain}{BaseRequest}{{0}}";
}

/// <summary>
Expand All @@ -46,23 +50,15 @@ public ElevenLabsSettingsInfo(string domain, string apiVersion = DefaultApiVersi
apiVersion = DefaultApiVersion;
}

var protocol = Https;

if (domain.StartsWith(Http))
{
protocol = Http;
domain = domain.Replace(Http, string.Empty);
}
else if (domain.StartsWith(Https))
{
protocol = Https;
domain = domain.Replace(Https, string.Empty);
}

Domain = $"{protocol}{domain}";
Domain = domain.Contains(Http)
? domain
: $"{Https}{domain}";
ApiVersion = apiVersion;
BaseRequest = $"/{ApiVersion}/";
BaseRequestUrlFormat = $"{Domain}{BaseRequest}{{0}}";
BaseWebSocketUrlFormat = Domain.Contains(Https)
? $"{WSS}{Domain}{BaseRequest}{{0}}"
: $"{WS}{Domain}{BaseRequest}{{0}}";
}

public string Domain { get; }
Expand All @@ -72,5 +68,11 @@ public ElevenLabsSettingsInfo(string domain, string apiVersion = DefaultApiVersi
public string BaseRequest { get; }

public string BaseRequestUrlFormat { get; }

internal string BaseWebSocketUrlFormat { get; }

private readonly Dictionary<string, string> defaultQueryParameters = new();

internal IReadOnlyDictionary<string, string> DefaultQueryParameters => defaultQueryParameters;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"GUID:7958db66189566541a6363568aee1575",
"GUID:d25c28436b1dcc9408d86f49a0f5210b",
"GUID:fe98ce187c2363b409d00954d687ec68",
"GUID:f7a0d77b5e1d79742a738fb859ee2f28"
"GUID:f7a0d77b5e1d79742a738fb859ee2f28",
"GUID:9fb4e1e06cb4c804ebfb0cff2b90e6d3"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
using ElevenLabs.VoiceGeneration;
using ElevenLabs.Voices;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Security.Authentication;
using Utilities.WebRequestRest;
using Utilities.WebSockets;

namespace ElevenLabs
{
public sealed class ElevenLabsClient : BaseClient<ElevenLabsAuthentication, ElevenLabsSettings>
public sealed class ElevenLabsClient : BaseClient<ElevenLabsAuthentication, ElevenLabsSettings>, IDisposable
{
/// <inheritdoc/>
public ElevenLabsClient(ElevenLabsConfiguration configuration)
Expand All @@ -36,6 +38,7 @@ public ElevenLabsClient(ElevenLabsConfiguration configuration)
public ElevenLabsClient(ElevenLabsAuthentication authentication = null, ElevenLabsSettings settings = null)
: base(authentication ?? ElevenLabsAuthentication.Default, settings ?? ElevenLabsSettings.Default)
{
//ElevenLabsSocket = new WebSocket(settings!.Info.WebSocketDomain);
UserEndpoint = new UserEndpoint(this);
VoicesEndpoint = new VoicesEndpoint(this);
ModelsEndpoint = new ModelsEndpoint(this);
Expand Down Expand Up @@ -83,6 +86,8 @@ protected override void ValidateAuthentication()
DefaultValueHandling = DefaultValueHandling.Ignore
};

internal WebSocket ElevenLabsSocket { get; }

public UserEndpoint UserEndpoint { get; }

public VoicesEndpoint VoicesEndpoint { get; }
Expand All @@ -100,5 +105,10 @@ protected override void ValidateAuthentication()
public DubbingEndpoint DubbingEndpoint { get; }

public SoundGenerationEndpoint SoundGenerationEndpoint { get; }

public void Dispose()
{
ElevenLabsSocket?.Dispose();
}
}
}
Loading