Skip to content

Commit

Permalink
ElevenLabs-DotNet 1.3.3 (#16)
Browse files Browse the repository at this point in the history
- Assign default voice names
- Get voice details if missing in tts
  • Loading branch information
StephenHodgson authored May 21, 2023
1 parent 3597639 commit fe699e9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
7 changes: 5 additions & 2 deletions ElevenLabs-DotNet/ElevenLabs-DotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
<Company>RageAgainstThePixel</Company>
<Copyright>2023</Copyright>
<PackageTags>ElevenLabs, AI, ML, Voice, TTS</PackageTags>
<Version>1.3.2</Version>
<PackageReleaseNotes>Version 1.3.2
<Version>1.3.3</Version>
<PackageReleaseNotes>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
Expand Down
13 changes: 11 additions & 2 deletions ElevenLabs-DotNet/TextToSpeech/TextToSpeechEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using ElevenLabs.Models;
using ElevenLabs.Voices;
using System;
using System.Diagnostics;
using System.IO;
using System.Text.Json;
using System.Threading;
Expand Down Expand Up @@ -43,9 +44,17 @@ public async Task<string> TextToSpeechAsync(string text, Voice voice, VoiceSetti
throw new ArgumentNullException(nameof(voice));
}

if (string.IsNullOrWhiteSpace(voice.Name))
{
Console.WriteLine("Voice details not found! To speed up this call, cache the voice details before making this request.");
voice = await Api.VoicesEndpoint.GetVoiceAsync(voice, cancellationToken: cancellationToken);
}

var rootDirectory = (saveDirectory ?? Directory.GetCurrentDirectory()).CreateNewDirectory(nameof(ElevenLabs));
var downloadDirectory = rootDirectory.CreateNewDirectory("TextToSpeech");
var fileName = $"{text.GenerateGuid()}.mp3";
var speechToTextDirectory = rootDirectory.CreateNewDirectory(nameof(TextToSpeech));
var downloadDirectory = speechToTextDirectory.CreateNewDirectory(voice.Name);
var clipGuid = $"{voice.Id}{text}".GenerateGuid().ToString();
var fileName = $"{clipGuid}.mp3";
var filePath = Path.Combine(downloadDirectory, fileName);

if (File.Exists(filePath) && deleteCachedFile)
Expand Down
18 changes: 9 additions & 9 deletions ElevenLabs-DotNet/Voices/Voice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,31 +52,31 @@ public Voice(string id)
#region Premade Voices

[JsonIgnore]
public static Voice Adam { get; } = new Voice("pNInz6obpgDQGcFmaJgB");
public static Voice Adam { get; } = new Voice("pNInz6obpgDQGcFmaJgB") { Name = nameof(Adam) };

[JsonIgnore]
public static Voice Antoni { get; } = new Voice("ErXwobaYiN019PkySvjV");
public static Voice Antoni { get; } = new Voice("ErXwobaYiN019PkySvjV") { Name = nameof(Antoni) };

[JsonIgnore]
public static Voice Arnold { get; } = new Voice("VR6AewLTigWG4xSOukaG");
public static Voice Arnold { get; } = new Voice("VR6AewLTigWG4xSOukaG") { Name = nameof(Arnold) };

[JsonIgnore]
public static Voice Bella { get; } = new Voice("EXAVITQu4vr4xnSDxMaL");
public static Voice Bella { get; } = new Voice("EXAVITQu4vr4xnSDxMaL") { Name = nameof(Bella) };

[JsonIgnore]
public static Voice Domi { get; } = new Voice("AZnzlk1XvdvUeBnXmlld");
public static Voice Domi { get; } = new Voice("AZnzlk1XvdvUeBnXmlld") { Name = nameof(Domi) };

[JsonIgnore]
public static Voice Elli { get; } = new Voice("MF3mGyEYCl7XYWbV9V6O");
public static Voice Elli { get; } = new Voice("MF3mGyEYCl7XYWbV9V6O") { Name = nameof(Elli) };

[JsonIgnore]
public static Voice Josh { get; } = new Voice("TxGEqnHWrfWFTfGW9XjX");
public static Voice Josh { get; } = new Voice("TxGEqnHWrfWFTfGW9XjX") { Name = nameof(Josh) };

[JsonIgnore]
public static Voice Rachel { get; } = new Voice("21m00Tcm4TlvDq8ikWAM");
public static Voice Rachel { get; } = new Voice("21m00Tcm4TlvDq8ikWAM") { Name = nameof(Rachel) };

[JsonIgnore]
public static Voice Sam { get; } = new Voice("yoZ06aMxZJJ28mfd3POQ");
public static Voice Sam { get; } = new Voice("yoZ06aMxZJJ28mfd3POQ") { Name = nameof(Sam) };

#endregion Premade Voices

Expand Down

0 comments on commit fe699e9

Please sign in to comment.