Skip to content

Commit

Permalink
com.rest.elevenlabs 3.1.1 (#50)
Browse files Browse the repository at this point in the history
- synced changes from dotnet package
- updated unit tests
- updated docs
  • Loading branch information
StephenHodgson committed Nov 29, 2023
1 parent bab230f commit 995de88
Show file tree
Hide file tree
Showing 32 changed files with 54 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Discord](https://img.shields.io/discord/855294214065487932.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.gg/xQgMW9ufN4) [![openupm](https://img.shields.io/npm/v/com.rest.elevenlabs?label=openupm&registry_uri=https://package.openupm.com)](https://openupm.com/packages/com.rest.elevenlabs/) [![openupm](https://img.shields.io/badge/dynamic/json?color=brightgreen&label=downloads&query=%24.downloads&suffix=%2Fmonth&url=https%3A%2F%2Fpackage.openupm.com%2Fdownloads%2Fpoint%2Flast-month%2Fcom.rest.elevenlabs)](https://openupm.com/packages/com.rest.elevenlabs/)

A non-official [ElevenLabs](https://elevenlabs.io) voice synthesis RESTful client for the [Unity](https://unity.com/) Game Engine.
A non-official [ElevenLabs](https://elevenlabs.io/?from=partnerbrown9849) voice synthesis RESTful client for the [Unity](https://unity.com/) Game Engine.

Based on [ElevenLabs-DotNet](https://github.com/RageAgainstThePixel/ElevenLabs-DotNet)

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions ElevenLabs/Packages/com.rest.elevenlabs/Runtime/Common.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ public enum OutputFormat
/// <remarks>
/// Requires you to be subscribed to Independent Publisher tier or above.
/// </remarks>
PCM_44100
PCM_44100,
/// <summary>
/// μ-law format (sometimes written mu-law, often approximated as u-law) with 8kHz sample rate.
/// </summary>
/// <remarks>
/// Note that this format is commonly used for Twilio audio inputs.
/// </remarks>
Ulaw_8000
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public async Task<HistoryItem> GetHistoryItemAsync(string id, CancellationToken
/// <summary>
/// Download audio of a history item.
/// </summary>
/// <param name="historyItem"><see cref="HistoryItem"/></param>
/// <param name="historyItem"><see cref="HistoryItem"/>.</param>
/// <param name="cancellationToken">Optional, <see cref="CancellationToken"/>.</param>
/// <returns><see cref="VoiceClip"/>.</returns>
public async Task<VoiceClip> DownloadHistoryAudioAsync(HistoryItem historyItem, CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

namespace ElevenLabs.Voice.Tests
namespace ElevenLabs.Tests
{
internal abstract class AbstractTestFixture
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using UnityEditor;
using UnityEngine;

namespace ElevenLabs.Voice.Tests
namespace ElevenLabs.Tests
{
internal class Test_Fixture_00_Authentication
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using NUnit.Framework;
using System.Threading.Tasks;

namespace ElevenLabs.Voice.Tests
namespace ElevenLabs.Tests
{
internal class Test_Fixture_01_UserEndpoint : AbstractTestFixture
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using UnityEditor;
using UnityEngine;

namespace ElevenLabs.Voice.Tests
namespace ElevenLabs.Tests
{
internal class Test_Fixture_02_VoicesEndpoint : AbstractTestFixture
{
Expand Down Expand Up @@ -118,8 +118,8 @@ public async Task Test_07_GetVoiceSample()
Assert.IsNotEmpty(updatedVoice.Samples);
var sample = updatedVoice.Samples.FirstOrDefault();
Assert.NotNull(sample);
var voiceClip = await ElevenLabsClient.VoicesEndpoint.DownloadVoiceSampleAudioAsync(updatedVoice, updatedVoice.Samples.FirstOrDefault());
Assert.NotNull(voiceClip);
var result = await ElevenLabsClient.VoicesEndpoint.DownloadVoiceSampleAudioAsync(updatedVoice, sample);
Assert.NotNull(result);
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Threading.Tasks;
using UnityEngine;

namespace ElevenLabs.Voice.Tests
namespace ElevenLabs.Tests
{
internal class Test_Fixture_03_TextToSpeechEndpoint : AbstractTestFixture
{
Expand All @@ -16,9 +16,11 @@ public async Task Test_01_TextToSpeech()
Assert.NotNull(ElevenLabsClient.TextToSpeechEndpoint);
var voice = Voices.Voice.Adam;
Assert.NotNull(voice);
var voiceClip = await ElevenLabsClient.TextToSpeechEndpoint.TextToSpeechAsync("The quick brown fox jumps over the lazy dog.", voice);
var defaultVoiceSettings = await ElevenLabsClient.VoicesEndpoint.GetDefaultVoiceSettingsAsync();
var voiceClip = await ElevenLabsClient.TextToSpeechEndpoint.TextToSpeechAsync("The quick brown fox jumps over the lazy dog.", voice, defaultVoiceSettings);
Assert.NotNull(voiceClip);
Assert.NotNull(voiceClip.AudioClip);
Debug.Log(voiceClip.CachedPath);
Debug.Log(voiceClip.Id);
}

[Test]
Expand All @@ -27,15 +29,16 @@ public async Task Test_02_StreamTextToSpeech()
Assert.NotNull(ElevenLabsClient.TextToSpeechEndpoint);
var voice = (await ElevenLabsClient.VoicesEndpoint.GetAllVoicesAsync()).FirstOrDefault();
Assert.NotNull(voice);
var defaultVoiceSettings = await ElevenLabsClient.VoicesEndpoint.GetDefaultVoiceSettingsAsync();
var partialClips = new Queue<AudioClip>();
var voiceClip = await ElevenLabsClient.TextToSpeechEndpoint.StreamTextToSpeechAsync(
"The quick brown fox jumps over the lazy dog.",
voice,
clip => partialClips.Enqueue(clip));
var voiceClip = await ElevenLabsClient.TextToSpeechEndpoint.StreamTextToSpeechAsync("The quick brown fox jumps over the lazy dog.", voice,
clip => partialClips.Enqueue(clip),
defaultVoiceSettings);
Assert.NotNull(partialClips);
Assert.IsNotEmpty(partialClips);
Assert.NotNull(voiceClip);
Assert.IsNotNull(voiceClip.AudioClip);
Debug.Log(voiceClip.Id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Threading.Tasks;
using UnityEngine;

namespace ElevenLabs.Voice.Tests
namespace ElevenLabs.Tests
{
internal class Test_Fixture_04_HistoryEndpoint : AbstractTestFixture
{
Expand Down Expand Up @@ -69,7 +69,7 @@ public async Task Test_04_DeleteHistoryItem()
foreach (var historyItem in itemsToDelete)
{
Debug.Log($"Deleting {historyItem.Id}...");
var result = await ElevenLabsClient.HistoryEndpoint.DeleteHistoryItemAsync(historyItem.Id);
var result = await ElevenLabsClient.HistoryEndpoint.DeleteHistoryItemAsync(historyItem);
Assert.NotNull(result);
Assert.IsTrue(result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using System.Threading.Tasks;
using UnityEngine;

namespace ElevenLabs.Voice.Tests
namespace ElevenLabs.Tests
{
internal class Test_Fixture_05_VoiceGeneration : AbstractTestFixture
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Threading.Tasks;
using UnityEngine;

namespace ElevenLabs.Voice.Tests
namespace ElevenLabs.Tests
{
internal class Test_Fixture_06_Models : AbstractTestFixture
{
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.1.0",
"version": "3.1.1",
"unity": "2021.3",
"documentationUrl": "https://github.com/RageAgainstThePixel/com.rest.elevenlabs#documentation",
"changelogUrl": "https://github.com/RageAgainstThePixel/com.rest.elevenlabs/releases",
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Discord](https://img.shields.io/discord/855294214065487932.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.gg/xQgMW9ufN4) [![openupm](https://img.shields.io/npm/v/com.rest.elevenlabs?label=openupm&registry_uri=https://package.openupm.com)](https://openupm.com/packages/com.rest.elevenlabs/) [![openupm](https://img.shields.io/badge/dynamic/json?color=brightgreen&label=downloads&query=%24.downloads&suffix=%2Fmonth&url=https%3A%2F%2Fpackage.openupm.com%2Fdownloads%2Fpoint%2Flast-month%2Fcom.rest.elevenlabs)](https://openupm.com/packages/com.rest.elevenlabs/)

A non-official [ElevenLabs](https://elevenlabs.io) voice synthesis RESTful client for the [Unity](https://unity.com/) Game Engine.
A non-official [ElevenLabs](https://elevenlabs.io/?from=partnerbrown9849) voice synthesis RESTful client for the [Unity](https://unity.com/) Game Engine.

Based on [ElevenLabs-DotNet](https://github.com/RageAgainstThePixel/ElevenLabs-DotNet)

Expand Down Expand Up @@ -265,7 +265,9 @@ audioSource.PlayOneShot(voiceClip.AudioClip);
voiceClip.CopyIntoProject(editorDownloadDirectory);
```

#### Stream Text to Speech
#### [Stream Text To Speech](https://docs.elevenlabs.io/api-reference/text-to-speech-stream)

Stream text to speech.

```csharp
var api = new ElevenLabsClient();
Expand Down Expand Up @@ -393,9 +395,9 @@ Get metadata about all your generated audio.

```csharp
var api = new ElevenLabsClient();
var historyInfo = await api.HistoryEndpoint.GetHistoryAsync();
var historyItems = await api.HistoryEndpoint.GetHistoryAsync();

foreach (var item in historyInfo.HistoryItems.OrderBy(item => item.Date))
foreach (var item in historyItems.OrderBy(historyItem => historyItem.Date))
{
Debug.Log($"{item.State} {item.Date} | {item.Id} | {item.Text.Length} | {item.Text}");
}
Expand All @@ -407,7 +409,7 @@ Get information about a specific item.

```csharp
var api = new ElevenLabsClient();
var historyItem = api.HistoryEndpoint.GetHistoryItemAsync(voiceClip.Id);
var historyItem = await api.HistoryEndpoint.GetHistoryItemAsync(voiceClip.Id);
```

#### Download History Audio
Expand Down

0 comments on commit 995de88

Please sign in to comment.