Skip to content

Commit

Permalink
ElevenLabs-DotNet 2.1.1 (#34)
Browse files Browse the repository at this point in the history
- Added VoicesEndpoint.GetAllVoicesAsync overload that allows skipping downloading the voice settings
  • Loading branch information
IS4Code authored Feb 15, 2024
1 parent da3200e commit 7ea80da
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
4 changes: 3 additions & 1 deletion ElevenLabs-DotNet/ElevenLabs-DotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
<Copyright>2023</Copyright>
<PackageTags>ElevenLabs, AI, ML, Voice, TTS</PackageTags>
<Version>2.1.0</Version>
<PackageReleaseNotes>Version 2.1.0
<PackageReleaseNotes>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
Expand Down
30 changes: 23 additions & 7 deletions ElevenLabs-DotNet/Voices/VoicesEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,45 @@ public VoicesEndpoint(ElevenLabsClient client) : base(client) { }

protected override string Root => "voices";

/// <summary>
/// Gets a list of all available voices for a user, and downloads all their settings.
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns><see cref="IReadOnlyList{T}"/> of <see cref="Voice"/>s.</returns>
public Task<IReadOnlyList<Voice>> GetAllVoicesAsync(CancellationToken cancellationToken = default)
{
return GetAllVoicesAsync(true, cancellationToken);
}

/// <summary>
/// Gets a list of all available voices for a user.
/// </summary>
/// <param name="downloadSettings">Whether to download all settings for the voices.</param>
/// <param name="cancellationToken"></param>
/// <returns><see cref="IReadOnlyList{T}"/> of <see cref="Voice"/>s.</returns>
public async Task<IReadOnlyList<Voice>> GetAllVoicesAsync(CancellationToken cancellationToken = default)
public async Task<IReadOnlyList<Voice>> 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<VoiceList>(responseAsString, ElevenLabsClient.JsonSerializationOptions).Voices;
var voiceSettingsTasks = new List<Task>();

foreach (var voice in voices)
if (downloadSettings)
{
voiceSettingsTasks.Add(Task.Run(LocalGetVoiceSettings, cancellationToken));
var voiceSettingsTasks = new List<Task>();

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();
}

Expand Down

0 comments on commit 7ea80da

Please sign in to comment.