From cce4288a13849b164880a1d1812edeb00f57ca1a Mon Sep 17 00:00:00 2001 From: Stephen Hodgson Date: Thu, 15 Feb 2024 13:28:23 -0500 Subject: [PATCH] ElevenLabs-DotNet 2.1.1 (#36) - Added VoicesEndpoint.GetAllVoicesAsync overload that allows skipping downloading the voice settings --------- Co-authored-by: IS4 Co-authored-by: Alizer <86959368+AlizerUncaged@users.noreply.github.com> --- ElevenLabs-DotNet/ElevenLabs-DotNet.csproj | 6 +++-- ElevenLabs-DotNet/Voices/VoicesEndpoint.cs | 30 +++++++++++++++++----- README.md | 2 +- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/ElevenLabs-DotNet/ElevenLabs-DotNet.csproj b/ElevenLabs-DotNet/ElevenLabs-DotNet.csproj index a22cdd6..831b40f 100644 --- a/ElevenLabs-DotNet/ElevenLabs-DotNet.csproj +++ b/ElevenLabs-DotNet/ElevenLabs-DotNet.csproj @@ -14,8 +14,10 @@ RageAgainstThePixel 2023 ElevenLabs, AI, ML, Voice, TTS - 2.1.0 - Version 2.1.0 + 2.1.1 + 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(); } diff --git a/README.md b/README.md index 2ef2ffb..f70299e 100644 --- a/README.md +++ b/README.md @@ -197,7 +197,7 @@ var text = "The quick brown fox jumps over the lazy dog."; var voice = (await api.VoicesEndpoint.GetAllVoicesAsync()).FirstOrDefault(); string fileName = "myfile.mp3"; using var outputFileStream = File.OpenWrite(fileName); -var voiceClip = await TextToSpeechAsync(text, voice, +var voiceClip = await api.TextToSpeechEndpoint.TextToSpeechAsync(text, voice, partialClipCallback: async (partialClip) => { // Write the incoming data to the output file stream.