Skip to content

Commit

Permalink
ElevenLabs-DotNet 1.0.4 (#9)
Browse files Browse the repository at this point in the history
- Updated authentication in docs
- Removed exception when sample item path is null or whitespace
- Updated unit tests so it doesn't delete useful history
  • Loading branch information
StephenHodgson authored Mar 24, 2023
1 parent bae3a11 commit 60b1686
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 50 deletions.
73 changes: 53 additions & 20 deletions .github/workflows/Publish-Nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,57 +11,90 @@ on:
- '*'
paths:
- ElevenLabs-DotNet/**
types:
- opened
- synchronize

workflow_dispatch:
inputs:
dotnet-version:
description: ".NET version to use"
required: false
default: "6.0.x"

env:
DOTNET_VERSION: ${{ github.event.inputs.dotnet-version || '6.0.x' }}

jobs:
build:
strategy:
matrix:
configuration: [Release]

if: ${{ !github.event_name == 'pull_request' || !github.event.pull_request.draft }}
runs-on: windows-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.x'

dotnet-version: ${{ env.DOTNET_VERSION }}
- uses: microsoft/setup-msbuild@v1

- name: Test Package ${{ matrix.configuration }}
run: dotnet test --configuration ${{ matrix.configuration }}
- name: Test Packages
run: dotnet test --configuration Release
if: ${{ github.ref != 'refs/heads/main' && github.event_name != 'push' }}
env:
ELEVEN_LABS_API_KEY: ${{ secrets.ELEVEN_LABS_API_KEY }}

- name: Publish Nuget Package
- name: Build Pack and Publish NuGet Package
run: |
$out = "${{ github.workspace }}\ElevenLabs-DotNet\bin\${{ matrix.configuration }}"
$projectPath = "${{ github.workspace }}\ElevenLabs-DotNet"
#$proxyProjectPath = "${{ github.workspace }}\ElevenLabs-DotNet-Proxy"
if (Test-Path -Path $out) {
$packagePath = Get-ChildItem -Path $out -File -Include '*.nupkg' -Recurse
}
# build all
dotnet build --configuration Release
if (Test-Path -Path $packagePath) {
# pack ElevenLabs-DotNet
dotnet pack $projectPath --configuration Release --include-symbols
$out = "$projectPath\bin\Release"
$packagePath = Get-ChildItem -Path $out -File -Include '*.nupkg' -Exclude '*symbols*' -Recurse -ErrorAction SilentlyContinue
if ($packagePath) {
Write-Host Package path: $packagePath
} else {
Write-Host Failed to find package at $packagePath
Write-Host Failed to find package at $out
exit 1
}
$isRelease = "${{ github.ref == 'refs/heads/main' && matrix.configuration == 'Release' }}"
# pack ElevenLabs-DotNet-Proxy
#dotnet pack $proxyProjectPath --configuration Release --include-symbols
#$proxyOut = "$proxyProjectPath\bin\Release"
#$proxyPackagePath = Get-ChildItem -Path $proxyOut -File -Include '*.nupkg' -Exclude '*symbols*' -Recurse -ErrorAction SilentlyContinue
#if ($proxyPackagePath) {
# Write-Host Package path: $proxyPackagePath
#} else {
# Write-Host Failed to find package at $proxyOut
# exit 1
#}
$isRelease = "${{ github.ref == 'refs/heads/main' }}"
if ($isRelease -eq 'true') {
dotnet nuget push $packagePath --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
dotnet nuget push $packagePath.FullName --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
#dotnet nuget push $proxyPackagePath.FullName --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
}
$version = $packagePath.Name -replace "^ElevenLabs-DotNet.(.*).nupkg$",'$1'
echo "PACKAGE_VERSION=$version" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
shell: pwsh

- uses: actions/upload-artifact@v3
if: always()
with:
name: Nuget Package ${{ matrix.configuration }}
path: ${{ github.workspace }}\ElevenLabs-DotNet\bin
name: ElevenLabs-DotNet.${{ env.PACKAGE_VERSION }}
path: |
${{ github.workspace }}/ElevenLabs-DotNet/bin/Release/ElevenLabs-DotNet.${{ env.PACKAGE_VERSION }}.nupkg
${{ github.workspace }}/ElevenLabs-DotNet/bin/Release/ElevenLabs-DotNet.${{ env.PACKAGE_VERSION }}.symbols.nupkg
#${{ github.workspace }}/ElevenLabs-DotNet/bin/Release/ElevenLabs-DotNet-Proxy.${{ env.PACKAGE_VERSION }}.nupkg
#${{ github.workspace }}/ElevenLabs-DotNet/bin/Release/ElevenLabs-DotNet-Proxy.${{ env.PACKAGE_VERSION }}.symbols.nupkg
if-no-files-found: ignore
25 changes: 12 additions & 13 deletions ElevenLabs-DotNet-Tests/ElevenLabs-DotNet-Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>ElevenLabs</RootNamespace>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>

<Nullable>disable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
<PackageReference Include="NUnit.Analyzers" Version="3.6.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<ProjectReference Include="..\ElevenLabs-DotNet\ElevenLabs-DotNet.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace ElevenLabs.Voice.Tests
{
internal class Test_Fixture_04_TextToSpeechEndpoint
internal class Test_Fixture_03_TextToSpeechEndpoint
{
[Test]
public async Task Test_01_TextToSpeech()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace ElevenLabs.Voice.Tests
{
internal class Test_Fixture_03_HistoryEndpoint
internal class Test_Fixture_04_HistoryEndpoint
{
[Test]
public async Task Test_01_GetHistory()
Expand Down Expand Up @@ -66,7 +66,7 @@ public async Task Test_04_DeleteHistoryItem()
var historyItems = await api.HistoryEndpoint.GetHistoryAsync();
Assert.NotNull(historyItems);
Assert.IsNotEmpty(historyItems);
var itemToDelete = historyItems.MinBy(item => item.Date);
var itemToDelete = historyItems.FirstOrDefault(item => item.Text.Contains("The quick brown fox jumps over the lazy dog."));
Assert.NotNull(itemToDelete);
Console.WriteLine($"Deleting {itemToDelete!.Id}...");
var result = await api.HistoryEndpoint.DeleteHistoryItemAsync(itemToDelete);
Expand Down
17 changes: 5 additions & 12 deletions ElevenLabs-DotNet/ElevenLabs-DotNet.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>latest</LangVersion>
Expand All @@ -13,10 +12,13 @@
<Authors>Stephen Hodgson</Authors>
<Title>ElevenLabs-DotNet</Title>
<Company>RageAgainstThePixel</Company>
<Version>1.0.3</Version>
<Version>1.0.4</Version>
<Copyright>2023</Copyright>
<PackageTags>ElevenLabs, AI, ML, Voice, TTS</PackageTags>
<PackageReleaseNotes>Release 1.0.3
<PackageReleaseNotes>Release 1.0.4
- Updated docs
- Removed exception when sample item path is null or whitespace
Release 1.0.3
- Updated DownloadHistoryItemsAsync to download all items if no ids are specified
- Updated docs
Release 1.0.2
Expand All @@ -32,16 +34,8 @@ Release 1.0.0
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.</Description>
<PackageIcon>ElevenLabsIcon.png</PackageIcon>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
<None Include="Assets\ElevenLabsIcon.png">
<Pack>True</Pack>
Expand All @@ -56,5 +50,4 @@ All copyrights, trademarks, logos, and assets are the property of their respecti
<PackagePath>\</PackagePath>
</None>
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions ElevenLabs-DotNet/Voices/VoicesEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public async Task<Voice> AddVoiceAsync(string name, IEnumerable<string> samplePa
{
if (string.IsNullOrWhiteSpace(sample))
{
throw new ArgumentNullException(nameof(sample));
continue;
}

var fileStream = File.OpenRead(sample);
Expand Down Expand Up @@ -198,7 +198,7 @@ public async Task<bool> EditVoiceAsync(Voice voice, IEnumerable<string> samplePa
{
if (string.IsNullOrWhiteSpace(sample))
{
throw new ArgumentNullException(nameof(sample));
continue;
}

var fileStream = File.OpenRead(sample);
Expand Down
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Install-Package ElevenLabs-DotNet

### Table of Contents

- [Authentication](#authentication)
- [Text to Speech](#text-to-speech)
- [Voices](#voices)
- [Get All Voices](#get-all-voices)
Expand All @@ -51,6 +52,56 @@ Install-Package ElevenLabs-DotNet
- [Get User Info](#get-user-info)
- [Get Subscription Info](#get-subscription-info)

### Authentication

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

1. [Pass keys directly with constructor](#pass-keys-directly-with-constructor)
2. [Load key from configuration file](#load-key-from-configuration-file)
3. [Use System Environment Variables](#use-system-environment-variables)

#### Pass keys directly with constructor

```csharp
var api = new ElevenLabsClient("yourApiKey");
```

Or create a `ElevenLabsAuthentication` object manually

```csharp
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

```json
{
"apiKey": "yourApiKey",
}
```

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

```csharp
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.

```csharp
var api = new ElevenLabsClient(ElevenLabsAuthentication.LoadFromEnv());
```

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

Convert text to speech.
Expand Down

0 comments on commit 60b1686

Please sign in to comment.