-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update disposable usages fix voice adding and editing
- Loading branch information
1 parent
06f49fe
commit cbd8d68
Showing
17 changed files
with
216 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
ElevenLabs-DotNet-Tests-Proxy/ElevenLabs-DotNet-Tests-Proxy.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace ElevenLabs.Voices | ||
{ | ||
public sealed class VoiceRequest : IDisposable | ||
{ | ||
public VoiceRequest(string name, string samplePath, IReadOnlyDictionary<string, string> labels = null, string description = null) | ||
: this(name, [samplePath], labels, description) | ||
{ | ||
} | ||
|
||
public VoiceRequest(string name, IEnumerable<string> samples, IReadOnlyDictionary<string, string> labels = null, string description = null) | ||
{ | ||
ArgumentException.ThrowIfNullOrWhiteSpace(name); | ||
ArgumentNullException.ThrowIfNull(samples); | ||
|
||
Name = name; | ||
Description = description; | ||
Labels = labels; | ||
Samples = samples.ToDictionary<string, string, Stream>(Path.GetFileName, File.OpenRead); | ||
} | ||
|
||
public VoiceRequest(string name, byte[] sample, IReadOnlyDictionary<string, string> labels = null, string description = null) | ||
: this(name, [sample], labels, description) | ||
{ | ||
} | ||
|
||
public VoiceRequest(string name, IEnumerable<byte[]> samples, IReadOnlyDictionary<string, string> labels = null, string description = null) | ||
{ | ||
ArgumentException.ThrowIfNullOrWhiteSpace(name); | ||
ArgumentNullException.ThrowIfNull(samples); | ||
|
||
Name = name; | ||
Description = description; | ||
Labels = labels; | ||
var count = 0; | ||
Samples = samples.ToDictionary<byte[], string, Stream>(_ => $"file-{count++}", sample => new MemoryStream(sample)); | ||
} | ||
|
||
public VoiceRequest(string name, Stream sample, IReadOnlyDictionary<string, string> labels = null, string description = null) | ||
: this(name, [sample], labels, description) | ||
{ | ||
} | ||
|
||
public VoiceRequest(string name, IEnumerable<Stream> samples, IReadOnlyDictionary<string, string> labels = null, string description = null) | ||
{ | ||
ArgumentException.ThrowIfNullOrWhiteSpace(name); | ||
ArgumentNullException.ThrowIfNull(samples); | ||
|
||
Name = name; | ||
Description = description; | ||
Labels = labels; | ||
var count = 0; | ||
Samples = samples.ToDictionary(_ => $"file-{count++}", sample => sample); | ||
} | ||
|
||
~VoiceRequest() => Dispose(false); | ||
|
||
public string Name { get; } | ||
|
||
public string Description { get; } | ||
|
||
public IReadOnlyDictionary<string, string> Labels { get; } | ||
|
||
public IReadOnlyDictionary<string, Stream> Samples { get; } | ||
|
||
private void Dispose(bool disposing) | ||
{ | ||
if (disposing) | ||
{ | ||
foreach (var (_, sample) in Samples) | ||
{ | ||
try | ||
{ | ||
sample?.Close(); | ||
sample?.Dispose(); | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine(e); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Dispose(true); | ||
GC.SuppressFinalize(this); | ||
} | ||
} | ||
} |
Oops, something went wrong.