Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ElevenLabs-DotNet 2.1.1 #36

Merged
merged 3 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading