ElevenLabs-DotNet 1.3.6

There is a newer version of this package available.
See the version list below for details.
dotnet add package ElevenLabs-DotNet --version 1.3.6                
NuGet\Install-Package ElevenLabs-DotNet -Version 1.3.6                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ElevenLabs-DotNet" Version="1.3.6" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ElevenLabs-DotNet --version 1.3.6                
#r "nuget: ElevenLabs-DotNet, 1.3.6"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ElevenLabs-DotNet as a Cake Addin
#addin nuget:?package=ElevenLabs-DotNet&version=1.3.6

// Install ElevenLabs-DotNet as a Cake Tool
#tool nuget:?package=ElevenLabs-DotNet&version=1.3.6                

ElevenLabs-DotNet

Discord NuGet version (ElevenLabs-DotNet) NuGet version (ElevenLabs-DotNet-Proxy) Nuget Publish

A non-official Eleven Labs voice synthesis RESTful client.

I am not affiliated with Eleven Labs and an account with api access is required.

All copyrights, trademarks, logos, and assets are the property of their respective owners.

Getting started

Install from NuGet

Install package ElevenLabs from Nuget. Here's how via command line:

Install-Package ElevenLabs-DotNet

Looking to use ElevenLabs in the Unity Game Engine? Check out our unity package on OpenUPM:

openupm


Documentation

Table of Contents

Authentication

There are 3 ways to provide your API keys, in order of precedence:

  1. Pass keys directly with constructor
  2. Load key from configuration file
  3. Use System Environment Variables
Pass keys directly with constructor
var api = new ElevenLabsClient("yourApiKey");

Or create a ElevenLabsAuthentication object manually

var api = new ElevenLabsClient(new ElevenLabsAuthentication("yourApiKey"));
Load key from configuration file

Attempts to load api keys from a configuration file, by default .elevenlabs in the current directory, optionally traversing up the directory tree or in the user's home directory.

To create a configuration file, create a new text file named .elevenlabs and containing the line:

Json format
{
  "apiKey": "yourApiKey",
}

You can also load the file directly with known path by calling a static method in Authentication:

var api = new ElevenLabsClient(ElevenLabsAuthentication.LoadFromDirectory("your/path/to/.elevenlabs"));;
Use System Environment Variables

Use your system's environment variables specify an api key to use.

  • Use ELEVEN_LABS_API_KEY for your api key.
var api = new ElevenLabsClient(ElevenLabsAuthentication.LoadFromEnv());

API Proxy

NuGet version (ElevenLabs-DotNet-Proxy)

Using either the ElevenLabs-DotNet or com.rest.elevenlabs packages directly in your front-end app may expose your API keys and other sensitive information. To mitigate this risk, it is recommended to set up an intermediate API that makes requests to ElevenLabs on behalf of your front-end app. This library can be utilized for both front-end and intermediary host configurations, ensuring secure communication with the ElevenLabs API.

Front End Example

In the front end example, you will need to securely authenticate your users using your preferred OAuth provider. Once the user is authenticated, exchange your custom auth token with your API key on the backend.

Follow these steps:

  1. Setup a new project using either the ElevenLabs-DotNet or com.rest.elevenlabs packages.
  2. Authenticate users with your OAuth provider.
  3. After successful authentication, create a new ElevenLabsAuthentication object and pass in the custom token.
  4. Create a new ElevenLabsClientSettings object and specify the domain where your intermediate API is located.
  5. Pass your new auth and settings objects to the ElevenLabsClient constructor when you create the client instance.

Here's an example of how to set up the front end:

var authToken = await LoginAsync();
var auth = new ElevenLabsAuthentication(authToken);
var settings = new ElevenLabsClientSettings(domain: "api.your-custom-domain.com");
var api = new ElevenLabsClient(auth, settings);

This setup allows your front end application to securely communicate with your backend that will be using the ElevenLabs-DotNet-Proxy, which then forwards requests to the ElevenLabs API. This ensures that your ElevenLabs API keys and other sensitive information remain secure throughout the process.

Back End Example

In this example, we demonstrate how to set up and use ElevenLabsProxyStartup in a new ASP.NET Core web app. The proxy server will handle authentication and forward requests to the ElevenLabs API, ensuring that your API keys and other sensitive information remain secure.

  1. Create a new ASP.NET Core minimal web API project.
  2. Add the ElevenLabs-DotNet nuget package to your project.
    • Powershell install: Install-Package ElevenLabs-DotNet-Proxy
    • Manually editing .csproj: <PackageReference Include="ElevenLabs-DotNet-Proxy" />
  3. Create a new class that inherits from AbstractAuthenticationFilter and override the ValidateAuthentication method. This will implement the IAuthenticationFilter that you will use to check user session token against your internal server.
  4. In Program.cs, create a new proxy web application by calling ElevenLabsProxyStartup.CreateDefaultHost method, passing your custom AuthenticationFilter as a type argument.
  5. Create ElevenLabsAuthentication and ElevenLabsClientSettings as you would normally with your API keys, org id, or Azure settings.
public partial class Program
{
    private class AuthenticationFilter : AbstractAuthenticationFilter
    {
        public override void ValidateAuthentication(IHeaderDictionary request)
        {
            // You will need to implement your own class to properly test
            // custom issued tokens you've setup for your end users.
            if (!request["xi-api-key"].ToString().Contains(userToken))
            {
                throw new AuthenticationException("User is not authorized");
            }
        }
    }

    public static void Main(string[] args)
    {
        var client = new ElevenLabsClient();
        var proxy = ElevenLabsProxyStartup.CreateDefaultHost<AuthenticationFilter>(args, client);
        proxy.Run();
    }
}

Once you have set up your proxy server, your end users can now make authenticated requests to your proxy api instead of directly to the ElevenLabs API. The proxy server will handle authentication and forward requests to the ElevenLabs API, ensuring that your API keys and other sensitive information remain secure.

Text to Speech

Convert text to speech.

var api = new ElevenLabsClient();
var text = "The quick brown fox jumps over the lazy dog.";
var voice = (await api.VoicesEndpoint.GetAllVoicesAsync()).FirstOrDefault();
var defaultVoiceSettings = await api.VoicesEndpoint.GetDefaultVoiceSettingsAsync();
var clipPath = await api.TextToSpeechEndpoint.TextToSpeechAsync(text, voice, defaultVoiceSettings);
Console.WriteLine(clipPath);

Note, only a single audio clip is created per text string. If you'd like to get different variations of the audio, you'll need to pass in deleteCachedFile: true.

Voices

Access to voices created either by the user or ElevenLabs.

Get All Voices

Gets a list of all available voices.

var api = new ElevenLabsClient();
var allVoices = await api.VoicesEndpoint.GetAllVoicesAsync();

foreach (var voice in allVoices)
{
    Console.WriteLine($"{voice.Id} | {voice.Name} | similarity boost: {voice.Settings?.SimilarityBoost} | stability: {voice.Settings?.Stability}");
}
Get Default Voice Settings

Gets the global default voice settings.

var api = new ElevenLabsClient();
var result = await api.VoicesEndpoint.GetDefaultVoiceSettingsAsync();
Console.WriteLine($"stability: {result.Stability} | similarity boost: {result.SimilarityBoost}");
Get Voice
var api = new ElevenLabsClient();
var voice = await api.VoicesEndpoint.GetVoiceAsync("voiceId");
Console.WriteLine($"{voice.Id} | {voice.Name} | {voice.PreviewUrl}");
Edit Voice Settings

Edit the settings for a specific voice.

var api = new ElevenLabsClient();
var success = await api.VoicesEndpoint.EditVoiceSettingsAsync(voice, new VoiceSettings(0.7f, 0.7f));
Console.WriteLine($"Was successful? {success}");
Add Voice
var api = new ElevenLabsClient();
var labels = new Dictionary<string, string>
{
    { "accent", "american" }
};
var audioSamplePaths = new List<string>();
var voice = await api.VoicesEndpoint.AddVoiceAsync("Voice Name", audioSamplePaths, labels);
Edit Voice
var api = new ElevenLabsClient();
var labels = new Dictionary<string, string>
{
    { "age", "young" }
};
var audioSamplePaths = new List<string>();
var success = await api.VoicesEndpoint.EditVoiceAsync(voice, audioSamplePaths, labels);
Console.WriteLine($"Was successful? {success}");
Delete Voice
var api = new ElevenLabsClient();
var success = await api.VoicesEndpoint.DeleteVoiceAsync(voiceId);
Console.WriteLine($"Was successful? {success}");
Samples

Access to your samples, created by you when cloning voices.

Get Voice Sample
var api = new ElevenLabsClient();
var clipPath = await api.VoicesEndpoint.GetVoiceSampleAsync(voiceId, sampleId);
Console.WriteLine(clipPath);
Delete Voice Sample
var api = new ElevenLabsClient();
var success = await api.VoicesEndpoint.DeleteVoiceSampleAsync(voiceId, sampleId);
Console.WriteLine($"Was successful? {success}");

History

Access to your previously synthesized audio clips including its metadata.

Get History
var api = new ElevenLabsClient();
var historyItems = await api.HistoryEndpoint.GetHistoryAsync();

foreach (var historyItem in historyItems.OrderBy(historyItem => historyItem.Date))
{
    Console.WriteLine($"{historyItem.State} {historyItem.Date} | {historyItem.Id} | {historyItem.Text.Length} | {historyItem.Text}");
}
Get History Audio
var api = new ElevenLabsClient();
var clipPath = await api.HistoryEndpoint.GetHistoryAudioAsync(historyItem);
Console.WriteLine(clipPath);
Download All History
var api = new ElevenLabsClient();
var success = await api.HistoryEndpoint.DownloadHistoryItemsAsync();
Delete History Item
var api = new ElevenLabsClient();
var result = await api.HistoryEndpoint.DeleteHistoryItemAsync(historyItem);
Console.WriteLine($"Was successful? {success}");

User

Access to your user Information and subscription status.

Get User Info

Gets information about your user account with ElevenLabs.

var api = new ElevenLabsClient();
var userInfo = await api.UserEndpoint.GetUserInfoAsync();
Get Subscription Info

Gets information about your subscription with ElevenLabs.

var api = new ElevenLabsClient();
var subscriptionInfo = await api.UserEndpoint.GetSubscriptionInfoAsync();
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on ElevenLabs-DotNet:

Package Downloads
FrostAura.Libraries.Intelligence.Semantic.Core

FrostAura Semantic Core provides structures and utilities to build language and hybrid applications.

ElevenLabs-DotNet-Proxy

A simple Proxy API gateway for ElevenLabs-DotNet to make authenticated requests from a front end application without exposing your API keys.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.1.0 2,847 9/14/2024
3.0.3 101 9/14/2024
3.0.2 364 9/3/2024
3.0.1 89 9/2/2024
3.0.0 187 9/2/2024
2.2.1 18,011 5/9/2024
2.2.0 185 5/6/2024
2.1.1 3,099 2/15/2024
2.1.0 2,220 11/29/2023
2.0.3 766 11/15/2023
2.0.2 161 11/14/2023
2.0.1 126 11/11/2023
2.0.0 255 10/29/2023
1.3.6 1,796 9/28/2023
1.3.5 1,388 7/14/2023
1.3.4 1,716 5/29/2023
1.3.3 557 5/21/2023
1.3.2 416 5/12/2023
1.3.0 206 5/1/2023
1.2.1 168 4/30/2023
1.2.0 164 4/30/2023
1.1.1 372 3/26/2023
1.1.0 202 3/26/2023
1.0.4 234 3/24/2023
1.0.3 234 3/13/2023
1.0.2 212 3/12/2023
1.0.1 218 3/11/2023
1.0.0 245 3/11/2023

Version 1.3.6
- Added Voice.HighQualityBaseModelIds
- Added CreateVoiceRequest.Description
Version 1.3.5
- Updated voice settings
Version 1.3.4
- Added VoiceSettings setters for convience
- Added voice validation in tts endpoint
Version 1.3.3
- Assign default voice names
- Get voice details if missing in tts
Version 1.3.2
- Added voice equality operators
- Added better parameter validation checks in Endpoints
Version 1.3.0
- Added ModelsEndpoint
- Updated TextToSpeech.TextToSpeechAsync with optional Model parameter. Defaults to eleven_monolingual_v1
Version 1.2.1
- Updated docs
Version 1.2.0
- Added ability to create voice from Id
- Refactored internal extension classes
- Fixed auth parsing
- Added ability to load configuration file from specific path
- Added optional parameter deleteCachedFile to TextToSpeechEndpoint.TextToSpeechAsync. Default is false
Version 1.1.0
- Added support for ElevenLabs-DotNet-Proxy
Version 1.0.4
- Updated docs
- Removed exception when sample item path is null or whitespace
Version 1.0.3
- Updated DownloadHistoryItemsAsync to download all items if no ids are specified
- Updated docs
Version 1.0.2
- Added VoiceGenerationEndpoint
- Added unit tests for voice design and instant voice cloning
- Updated docs
Version 1.0.1
- Updated docs
Version 1.0.0
- Initial Release!