From 2390547e1cd8e02e224c70d7de33ab67debf681e Mon Sep 17 00:00:00 2001 From: IS4 Date: Thu, 15 Feb 2024 15:19:00 +0100 Subject: [PATCH 1/4] GetAllVoicesAsync overload that does not download settings --- ElevenLabs-DotNet/Voices/VoicesEndpoint.cs | 30 +++++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/ElevenLabs-DotNet/Voices/VoicesEndpoint.cs b/ElevenLabs-DotNet/Voices/VoicesEndpoint.cs index d4134ff..375635c 100644 --- a/ElevenLabs-DotNet/Voices/VoicesEndpoint.cs +++ b/ElevenLabs-DotNet/Voices/VoicesEndpoint.cs @@ -36,29 +36,45 @@ public VoicesEndpoint(ElevenLabsClient client) : base(client) { } protected override string Root => "voices"; + /// + /// Gets a list of all available voices for a user, and downloads all their settings. + /// + /// + /// of s. + public Task> GetAllVoicesAsync(CancellationToken cancellationToken = default) + { + return GetAllVoicesAsync(true, cancellationToken); + } + /// /// Gets a list of all available voices for a user. /// + /// Whether to download all settings for the voices. /// /// of s. - public async Task> GetAllVoicesAsync(CancellationToken cancellationToken = default) + public async Task> GetAllVoicesAsync(bool downloadSettings, CancellationToken cancellationToken = default) { var response = await client.Client.GetAsync(GetUrl(), cancellationToken).ConfigureAwait(false); var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false); var voices = JsonSerializer.Deserialize(responseAsString, ElevenLabsClient.JsonSerializationOptions).Voices; - var voiceSettingsTasks = new List(); - foreach (var voice in voices) + if (downloadSettings) { - voiceSettingsTasks.Add(Task.Run(LocalGetVoiceSettings, cancellationToken)); + var voiceSettingsTasks = new List(); - async Task LocalGetVoiceSettings() + foreach(var voice in voices) { - voice.Settings = await GetVoiceSettingsAsync(voice, cancellationToken).ConfigureAwait(false); + voiceSettingsTasks.Add(Task.Run(LocalGetVoiceSettings, cancellationToken)); + + async Task LocalGetVoiceSettings() + { + voice.Settings = await GetVoiceSettingsAsync(voice, cancellationToken).ConfigureAwait(false); + } } + + await Task.WhenAll(voiceSettingsTasks).ConfigureAwait(false); } - await Task.WhenAll(voiceSettingsTasks).ConfigureAwait(false); return voices.ToList(); } From 3ee24d258346837938d4dce9a71592ea9f2aa292 Mon Sep 17 00:00:00 2001 From: IS4 Date: Thu, 15 Feb 2024 15:22:26 +0100 Subject: [PATCH 2/4] update version --- ElevenLabs-DotNet/ElevenLabs-DotNet.csproj | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ElevenLabs-DotNet/ElevenLabs-DotNet.csproj b/ElevenLabs-DotNet/ElevenLabs-DotNet.csproj index a22cdd6..cc0e2dc 100644 --- a/ElevenLabs-DotNet/ElevenLabs-DotNet.csproj +++ b/ElevenLabs-DotNet/ElevenLabs-DotNet.csproj @@ -15,7 +15,9 @@ 2023 ElevenLabs, AI, ML, Voice, TTS 2.1.0 - Version 2.1.0 + Version 2.1.1 +- Added VoicesEndpoint.GetAllVoicesAsync overload that allows skipping downloading the voice settings +Version 2.1.0 - Added ElevenLabsClient.EnableDebug option to enable and disable for all endpoints - Synced changes from unity package - Updated unit test From e4471e0343b775a4a04261979d622bddf6b2136c Mon Sep 17 00:00:00 2001 From: IS4 Date: Thu, 15 Feb 2024 16:42:21 +0100 Subject: [PATCH 3/4] style fix --- ElevenLabs-DotNet/Voices/VoicesEndpoint.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ElevenLabs-DotNet/Voices/VoicesEndpoint.cs b/ElevenLabs-DotNet/Voices/VoicesEndpoint.cs index 375635c..d914a17 100644 --- a/ElevenLabs-DotNet/Voices/VoicesEndpoint.cs +++ b/ElevenLabs-DotNet/Voices/VoicesEndpoint.cs @@ -62,7 +62,7 @@ public async Task> GetAllVoicesAsync(bool downloadSettings, { var voiceSettingsTasks = new List(); - foreach(var voice in voices) + foreach (var voice in voices) { voiceSettingsTasks.Add(Task.Run(LocalGetVoiceSettings, cancellationToken)); From 97b2cefedc753765b9eab1a17c674c981d80339f Mon Sep 17 00:00:00 2001 From: IS4 Date: Thu, 15 Feb 2024 18:21:09 +0100 Subject: [PATCH 4/4] incorporate suggested changes --- ElevenLabs-DotNet/Voices/VoicesEndpoint.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ElevenLabs-DotNet/Voices/VoicesEndpoint.cs b/ElevenLabs-DotNet/Voices/VoicesEndpoint.cs index d914a17..cdbeaad 100644 --- a/ElevenLabs-DotNet/Voices/VoicesEndpoint.cs +++ b/ElevenLabs-DotNet/Voices/VoicesEndpoint.cs @@ -64,9 +64,9 @@ public async Task> GetAllVoicesAsync(bool downloadSettings, foreach (var voice in voices) { - voiceSettingsTasks.Add(Task.Run(LocalGetVoiceSettings, cancellationToken)); + voiceSettingsTasks.Add(Task.Run(LocalGetVoiceSettingsAsync, cancellationToken)); - async Task LocalGetVoiceSettings() + async Task LocalGetVoiceSettingsAsync() { voice.Settings = await GetVoiceSettingsAsync(voice, cancellationToken).ConfigureAwait(false); }