Skip to content

Commit

Permalink
com.rest.elevenlabs 3.2.7 (#72)
Browse files Browse the repository at this point in the history
- enable optional settings download when requesting all voices

---------

Co-authored-by: Stephen Hodgson <rage.against.the.pixel@gmail.com>
  • Loading branch information
IS4Code and StephenHodgson committed Feb 15, 2024
1 parent c924df9 commit fce1412
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,46 @@ public VoiceResponse([JsonProperty("voice_id")] string voiceId)

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 Rest.GetAsync(GetUrl(), new RestParameters(client.DefaultRequestHeaders), cancellationToken);
response.Validate(EnableDebug);
var voices = JsonConvert.DeserializeObject<VoiceList>(response.Body, ElevenLabsClient.JsonSerializationOptions).Voices;
var voiceSettingsTasks = new List<Task>();

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

async Task LocalGetVoiceSettings()
foreach (var voice in voices)
{
voice.Settings = await GetVoiceSettingsAsync(voice, cancellationToken).ConfigureAwait(true);
voiceSettingsTasks.Add(LocalGetVoiceSettingsAsync());

async Task LocalGetVoiceSettingsAsync()
{
await Awaiters.UnityMainThread;
voice.Settings = await GetVoiceSettingsAsync(voice, cancellationToken).ConfigureAwait(true);
}
}

await Task.WhenAll(voiceSettingsTasks).ConfigureAwait(true);
}

await Task.WhenAll(voiceSettingsTasks).ConfigureAwait(true);
return voices.ToList();
}

Expand Down
2 changes: 1 addition & 1 deletion ElevenLabs/Packages/com.rest.elevenlabs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "ElevenLabs",
"description": "A non-official Eleven Labs voice synthesis RESTful client.",
"keywords": [],
"version": "3.2.6",
"version": "3.2.7",
"unity": "2021.3",
"documentationUrl": "https://github.com/RageAgainstThePixel/com.rest.elevenlabs#documentation",
"changelogUrl": "https://github.com/RageAgainstThePixel/com.rest.elevenlabs/releases",
Expand Down

0 comments on commit fce1412

Please sign in to comment.