From 7ea80dae82b065eafc505829fcea7de3b56dff75 Mon Sep 17 00:00:00 2001 From: IS4 Date: Thu, 15 Feb 2024 18:24:40 +0100 Subject: [PATCH] ElevenLabs-DotNet 2.1.1 (#34) - Added VoicesEndpoint.GetAllVoicesAsync overload that allows skipping downloading the voice settings --- ElevenLabs-DotNet/ElevenLabs-DotNet.csproj | 4 ++- ElevenLabs-DotNet/Voices/VoicesEndpoint.cs | 30 +++++++++++++++++----- 2 files changed, 26 insertions(+), 8 deletions(-) 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 diff --git a/ElevenLabs-DotNet/Voices/VoicesEndpoint.cs b/ElevenLabs-DotNet/Voices/VoicesEndpoint.cs index d4134ff..cdbeaad 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(LocalGetVoiceSettingsAsync, cancellationToken)); + + async Task LocalGetVoiceSettingsAsync() + { + voice.Settings = await GetVoiceSettingsAsync(voice, cancellationToken).ConfigureAwait(false); + } } + + await Task.WhenAll(voiceSettingsTasks).ConfigureAwait(false); } - await Task.WhenAll(voiceSettingsTasks).ConfigureAwait(false); return voices.ToList(); }