Skip to content

Commit

Permalink
ElevenLabs-DotNet 2.1.1 (#36)
Browse files Browse the repository at this point in the history
- Added VoicesEndpoint.GetAllVoicesAsync overload that allows skipping downloading the voice settings

---------

Co-authored-by: IS4 <[email protected]>
Co-authored-by: Alizer <[email protected]>
  • Loading branch information
3 people authored Feb 15, 2024
1 parent da3200e commit cce4288
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 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.1.0</Version>
<PackageReleaseNotes>Version 2.1.0
<Version>2.1.1</Version>
<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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit cce4288

Please sign in to comment.