Skip to content

Commit

Permalink
ElevenLabs-DotNet 2.0.1 (#27)
Browse files Browse the repository at this point in the history
- Pass some cancellation tokens to internals
  • Loading branch information
StephenHodgson authored Nov 11, 2023
1 parent e488bba commit 1828fe8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
6 changes: 4 additions & 2 deletions ElevenLabs-DotNet/ElevenLabs-DotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
<Company>RageAgainstThePixel</Company>
<Copyright>2023</Copyright>
<PackageTags>ElevenLabs, AI, ML, Voice, TTS</PackageTags>
<Version>2.0.0</Version>
<PackageReleaseNotes>Version 2.0.0
<Version>2.0.1</Version>
<PackageReleaseNotes>Version 2.0.1
- Pass some cancellation tokens to internals
Version 2.0.0
Refactoring to support latest API changes
- Biggest Change is the new VoiceClip signature for all endpoints which contains all the information about the generated clip.
- Refactored HistoryEndpoint
Expand Down
4 changes: 2 additions & 2 deletions ElevenLabs-DotNet/Extensions/HttpResponseMessageExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ namespace ElevenLabs.Extensions
{
internal static class HttpResponseMessageExtensions
{
public static async Task<string> ReadAsStringAsync(this HttpResponseMessage response, bool debugResponse = false, [CallerMemberName] string methodName = null)
public static async Task<string> ReadAsStringAsync(this HttpResponseMessage response, bool debugResponse = false, CancellationToken cancellationToken = default, [CallerMemberName] string methodName = null)
{
var responseAsString = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var responseAsString = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);

if (!response.IsSuccessStatusCode)
{
Expand Down
6 changes: 3 additions & 3 deletions ElevenLabs-DotNet/History/HistoryEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task<HistoryInfo> GetHistoryAsync(int? pageSize = null, string star
}

var response = await Api.Client.GetAsync(GetUrl(queryParameters: parameters), cancellationToken);
var responseAsString = await response.ReadAsStringAsync(EnableDebug);
var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken: cancellationToken);
return JsonSerializer.Deserialize<HistoryInfo>(responseAsString, ElevenLabsClient.JsonSerializationOptions);
}

Expand All @@ -56,7 +56,7 @@ public async Task<HistoryInfo> GetHistoryAsync(int? pageSize = null, string star
public async Task<HistoryItem> GetHistoryItemAsync(string id, CancellationToken cancellationToken = default)
{
var response = await Api.Client.GetAsync(GetUrl($"/{id}"), cancellationToken);
var responseAsString = await response.ReadAsStringAsync(EnableDebug);
var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken: cancellationToken);
return JsonSerializer.Deserialize<HistoryItem>(responseAsString, ElevenLabsClient.JsonSerializationOptions);
}

Expand Down Expand Up @@ -98,7 +98,7 @@ public async Task<VoiceClip> DownloadHistoryAudioAsync(HistoryItem historyItem,
public async Task<bool> DeleteHistoryItemAsync(string id, CancellationToken cancellationToken = default)
{
var response = await Api.Client.DeleteAsync(GetUrl($"/{id}"), cancellationToken);
await response.ReadAsStringAsync(EnableDebug);
await response.ReadAsStringAsync(EnableDebug, cancellationToken: cancellationToken);
return response.IsSuccessStatusCode;
}

Expand Down
4 changes: 2 additions & 2 deletions ElevenLabs-DotNet/VoiceGeneration/VoiceGenerationEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public VoiceGenerationEndpoint(ElevenLabsClient api) : base(api) { }
public async Task<GeneratedVoiceOptions> GetVoiceGenerationOptionsAsync(CancellationToken cancellationToken = default)
{
var response = await Api.Client.GetAsync(GetUrl("/generate-voice/parameters"), cancellationToken);
var responseAsString = await response.ReadAsStringAsync(EnableDebug);
var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken: cancellationToken);
return JsonSerializer.Deserialize<GeneratedVoiceOptions>(responseAsString, ElevenLabsClient.JsonSerializationOptions);
}

Expand Down Expand Up @@ -66,7 +66,7 @@ public async Task<Voice> CreateVoiceAsync(CreateVoiceRequest createVoiceRequest,
{
var payload = JsonSerializer.Serialize(createVoiceRequest).ToJsonStringContent();
var response = await Api.Client.PostAsync(GetUrl("/create-voice"), payload, cancellationToken);
var responseAsString = await response.ReadAsStringAsync(EnableDebug);
var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken: cancellationToken);
return JsonSerializer.Deserialize<Voice>(responseAsString, ElevenLabsClient.JsonSerializationOptions);
}
}
Expand Down
12 changes: 6 additions & 6 deletions ElevenLabs-DotNet/Voices/VoicesEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public VoicesEndpoint(ElevenLabsClient api) : base(api) { }
public async Task<IReadOnlyList<Voice>> GetAllVoicesAsync(CancellationToken cancellationToken = default)
{
var response = await Api.Client.GetAsync(GetUrl(), cancellationToken).ConfigureAwait(false);
var responseAsString = await response.ReadAsStringAsync(EnableDebug).ConfigureAwait(false);
var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false);
var voices = JsonSerializer.Deserialize<VoiceList>(responseAsString, ElevenLabsClient.JsonSerializationOptions).Voices;
var voiceSettingsTasks = new List<Task>();

Expand All @@ -70,7 +70,7 @@ async Task LocalGetVoiceSettings()
public async Task<VoiceSettings> GetDefaultVoiceSettingsAsync(CancellationToken cancellationToken = default)
{
var response = await Api.Client.GetAsync(GetUrl("/settings/default"), cancellationToken).ConfigureAwait(false);
var responseAsString = await response.ReadAsStringAsync(EnableDebug).ConfigureAwait(false);
var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false);
return JsonSerializer.Deserialize<VoiceSettings>(responseAsString, ElevenLabsClient.JsonSerializationOptions);
}

Expand All @@ -88,7 +88,7 @@ public async Task<VoiceSettings> GetVoiceSettingsAsync(string voiceId, Cancellat
}

var response = await Api.Client.GetAsync(GetUrl($"/{voiceId}/settings"), cancellationToken).ConfigureAwait(false);
var responseAsString = await response.ReadAsStringAsync(EnableDebug).ConfigureAwait(false);
var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false);
return JsonSerializer.Deserialize<VoiceSettings>(responseAsString, ElevenLabsClient.JsonSerializationOptions);
}

Expand All @@ -107,7 +107,7 @@ public async Task<Voice> GetVoiceAsync(string voiceId, bool withSettings = false
}

var response = await Api.Client.GetAsync(GetUrl($"/{voiceId}?with_settings={withSettings}"), cancellationToken).ConfigureAwait(false);
var responseAsString = await response.ReadAsStringAsync(EnableDebug).ConfigureAwait(false);
var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false);
return JsonSerializer.Deserialize<Voice>(responseAsString, ElevenLabsClient.JsonSerializationOptions);
}

Expand All @@ -127,7 +127,7 @@ public async Task<bool> EditVoiceSettingsAsync(string voiceId, VoiceSettings voi

var payload = JsonSerializer.Serialize(voiceSettings).ToJsonStringContent();
var response = await Api.Client.PostAsync(GetUrl($"/{voiceId}/settings/edit"), payload, cancellationToken).ConfigureAwait(false);
await response.ReadAsStringAsync(EnableDebug).ConfigureAwait(false);
await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false);
return response.IsSuccessStatusCode;
}

Expand Down Expand Up @@ -182,7 +182,7 @@ public async Task<Voice> AddVoiceAsync(string name, IEnumerable<string> samplePa
}

var response = await Api.Client.PostAsync(GetUrl("/add"), form, cancellationToken).ConfigureAwait(false);
var responseAsString = await response.ReadAsStringAsync(EnableDebug).ConfigureAwait(false);
var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false);
var voiceResponse = JsonSerializer.Deserialize<VoiceResponse>(responseAsString, ElevenLabsClient.JsonSerializationOptions);
return await GetVoiceAsync(voiceResponse.VoiceId, cancellationToken: cancellationToken).ConfigureAwait(false);
}
Expand Down

0 comments on commit 1828fe8

Please sign in to comment.