diff --git a/.github/workflows/Publish-Nuget.yml b/.github/workflows/Publish-Nuget.yml index b4b1753..97d7f43 100644 --- a/.github/workflows/Publish-Nuget.yml +++ b/.github/workflows/Publish-Nuget.yml @@ -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 diff --git a/ElevenLabs-DotNet-Tests/ElevenLabs-DotNet-Tests.csproj b/ElevenLabs-DotNet-Tests/ElevenLabs-DotNet-Tests.csproj index 2d83891..8128d46 100644 --- a/ElevenLabs-DotNet-Tests/ElevenLabs-DotNet-Tests.csproj +++ b/ElevenLabs-DotNet-Tests/ElevenLabs-DotNet-Tests.csproj @@ -1,24 +1,23 @@ - - + net6.0 ElevenLabs disable - enable - + disable false - - + - - - - - - + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + - diff --git a/ElevenLabs-DotNet-Tests/Test_Fixture_04_TextToSpeechEndpoint.cs b/ElevenLabs-DotNet-Tests/Test_Fixture_03_TextToSpeechEndpoint.cs similarity index 94% rename from ElevenLabs-DotNet-Tests/Test_Fixture_04_TextToSpeechEndpoint.cs rename to ElevenLabs-DotNet-Tests/Test_Fixture_03_TextToSpeechEndpoint.cs index 5c6e3cf..fc006f6 100644 --- a/ElevenLabs-DotNet-Tests/Test_Fixture_04_TextToSpeechEndpoint.cs +++ b/ElevenLabs-DotNet-Tests/Test_Fixture_03_TextToSpeechEndpoint.cs @@ -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() diff --git a/ElevenLabs-DotNet-Tests/Test_Fixture_03_HistoryEndpoint.cs b/ElevenLabs-DotNet-Tests/Test_Fixture_04_HistoryEndpoint.cs similarity index 94% rename from ElevenLabs-DotNet-Tests/Test_Fixture_03_HistoryEndpoint.cs rename to ElevenLabs-DotNet-Tests/Test_Fixture_04_HistoryEndpoint.cs index dd27990..398b540 100644 --- a/ElevenLabs-DotNet-Tests/Test_Fixture_03_HistoryEndpoint.cs +++ b/ElevenLabs-DotNet-Tests/Test_Fixture_04_HistoryEndpoint.cs @@ -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() @@ -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); diff --git a/ElevenLabs-DotNet/ElevenLabs-DotNet.csproj b/ElevenLabs-DotNet/ElevenLabs-DotNet.csproj index 74216cf..8e772d0 100644 --- a/ElevenLabs-DotNet/ElevenLabs-DotNet.csproj +++ b/ElevenLabs-DotNet/ElevenLabs-DotNet.csproj @@ -1,5 +1,4 @@ - net6.0 latest @@ -13,10 +12,13 @@ Stephen Hodgson ElevenLabs-DotNet RageAgainstThePixel - 1.0.3 + 1.0.4 2023 ElevenLabs, AI, ML, Voice, TTS - Release 1.0.3 + 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 @@ -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. ElevenLabsIcon.png - - - - True - - - True - True @@ -56,5 +50,4 @@ All copyrights, trademarks, logos, and assets are the property of their respecti \ - diff --git a/ElevenLabs-DotNet/Voices/VoicesEndpoint.cs b/ElevenLabs-DotNet/Voices/VoicesEndpoint.cs index 5aa2d76..8e49870 100644 --- a/ElevenLabs-DotNet/Voices/VoicesEndpoint.cs +++ b/ElevenLabs-DotNet/Voices/VoicesEndpoint.cs @@ -144,7 +144,7 @@ public async Task AddVoiceAsync(string name, IEnumerable samplePa { if (string.IsNullOrWhiteSpace(sample)) { - throw new ArgumentNullException(nameof(sample)); + continue; } var fileStream = File.OpenRead(sample); @@ -198,7 +198,7 @@ public async Task EditVoiceAsync(Voice voice, IEnumerable samplePa { if (string.IsNullOrWhiteSpace(sample)) { - throw new ArgumentNullException(nameof(sample)); + continue; } var fileStream = File.OpenRead(sample); diff --git a/README.md b/README.md index 8b2b510..c12f0b2 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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.