Skip to content

Commit

Permalink
com.rest.elevenlabs 3.3.1 (#96)
Browse files Browse the repository at this point in the history
- Fix DubbingRequest.DropBackgroundAudio flag not properly being set
- Added DubbingRequest.UseProfanityFilter flag
- Added previous text input parameter to TextToSpeechRequest

---------

Co-authored-by: Benjamin van der Wolf <[email protected]>
  • Loading branch information
StephenHodgson and Bvanderwolf authored Sep 14, 2024
1 parent febc99d commit e7f175b
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ public async Task<DubbingProjectMetadata> DubAsync(DubbingRequest request, int?
{
payload.AddField("highest_resolution", request.HighestResolution.Value.ToString());
}

if (request.DropBackgroundAudio.HasValue)
{
payload.AddField("drop_background_audio", request.DropBackgroundAudio.ToString().ToLower());
}

if (request.UseProfanityFilter.HasValue)
{
payload.AddField("use_profanity_filter", request.UseProfanityFilter.ToString().ToLower());
}
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ public DubbingRequest(
int? endTime = null,
bool? highestResolution = null,
bool? dropBackgroundAudio = null,
bool? useProfanityFilter = null,
string projectName = null)
: this(new[] { filePath }, targetLanguage, sourceLanguage, numberOfSpeakers, watermark, startTime, endTime, highestResolution, dropBackgroundAudio, projectName)
: this(new[] { filePath }, targetLanguage, sourceLanguage, numberOfSpeakers, watermark, startTime, endTime, highestResolution, dropBackgroundAudio, useProfanityFilter, projectName)
{
}

Expand All @@ -36,8 +37,9 @@ public DubbingRequest(
int? endTime = null,
bool? highestResolution = null,
bool? dropBackgroundAudio = null,
bool? useProfanityFilter = null,
string projectName = null)
: this(targetLanguage, null, filePaths, sourceLanguage, numberOfSpeakers, watermark, startTime, endTime, highestResolution, dropBackgroundAudio, projectName)
: this(targetLanguage, null, filePaths, sourceLanguage, numberOfSpeakers, watermark, startTime, endTime, highestResolution, dropBackgroundAudio, useProfanityFilter, projectName)
{
}

Expand All @@ -51,17 +53,29 @@ public DubbingRequest(
int? endTime = null,
bool? highestResolution = null,
bool? dropBackgroundAudio = null,
bool? useProfanityFilter = null,
string projectName = null)
: this(targetLanguage, sourceUrl, null, sourceLanguage, numberOfSpeakers, watermark, startTime, endTime, highestResolution, dropBackgroundAudio, projectName)
: this(targetLanguage, sourceUrl, null, sourceLanguage, numberOfSpeakers, watermark, startTime, endTime, highestResolution, dropBackgroundAudio, useProfanityFilter, projectName)
{
}

public DubbingRequest(AudioClip audioClip, string targetLanguage, string sourceLanguage = null, int? numberOfSpeakers = null, bool? watermark = null, int? startTime = null, int? endTime = null, bool? highestResolution = null, bool? dropBackgroundAudio = null, string projectName = null)
: this(new[] { audioClip }, targetLanguage, sourceLanguage, numberOfSpeakers, watermark, startTime, endTime, highestResolution, dropBackgroundAudio, projectName)
public DubbingRequest(AudioClip audioClip, string targetLanguage, string sourceLanguage = null, int? numberOfSpeakers = null, bool? watermark = null, int? startTime = null, int? endTime = null, bool? highestResolution = null, bool? dropBackgroundAudio = null, bool? useProfanityFilter = null, string projectName = null)
: this(new[] { audioClip }, targetLanguage, sourceLanguage, numberOfSpeakers, watermark, startTime, endTime, highestResolution, dropBackgroundAudio, useProfanityFilter, projectName)
{
}

public DubbingRequest(IEnumerable<AudioClip> audioClips, string targetLanguage, string sourceLanguage = null, int? numberOfSpeakers = null, bool? watermark = null, int? startTime = null, int? endTime = null, bool? highestResolution = null, bool? dropBackgroundAudio = null, string projectName = null)
public DubbingRequest(
IEnumerable<AudioClip> audioClips,
string targetLanguage,
string sourceLanguage = null,
int? numberOfSpeakers = null,
bool? watermark = null,
int? startTime = null,
int? endTime = null,
bool? highestResolution = null,
bool? dropBackgroundAudio = null,
bool? useProfanityFilter = null,
string projectName = null)
{
if (audioClips == null)
{
Expand All @@ -88,6 +102,7 @@ public DubbingRequest(IEnumerable<AudioClip> audioClips, string targetLanguage,
EndTime = endTime;
HighestResolution = highestResolution;
DropBackgroundAudio = dropBackgroundAudio;
UseProfanityFilter = useProfanityFilter;
ProjectName = projectName;
var files = new List<(string, string, Stream)>(clips.Count);
files.AddRange((from audioClip in clips let stream = new MemoryStream(audioClip.EncodeToWav()) select (audioClip.name, "audio/wav", stream)).Select(value => ((string, string, Stream))value));
Expand All @@ -105,6 +120,7 @@ private DubbingRequest(
int? endTime = null,
bool? highestResolution = null,
bool? dropBackgroundAudio = null,
bool? useProfanityFilter = null,
string projectName = null)
{
if (string.IsNullOrWhiteSpace(targetLanguage))
Expand Down Expand Up @@ -167,6 +183,7 @@ private DubbingRequest(
EndTime = endTime;
HighestResolution = highestResolution;
DropBackgroundAudio = dropBackgroundAudio;
UseProfanityFilter = useProfanityFilter;
ProjectName = projectName;
}

Expand Down Expand Up @@ -229,6 +246,11 @@ private DubbingRequest(
/// </summary>
public bool? DropBackgroundAudio { get; }

/// <summary>
/// [BETA] Whether transcripts should have profanities censored with the words '[censored]'.
/// </summary>
public bool? UseProfanityFilter { get; }

/// <summary>
/// Name of the dubbing project.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ namespace ElevenLabs.TextToSpeech
public sealed class TextToSpeechRequest
{
[Preserve]
public TextToSpeechRequest(Voice voice, string text, Encoding encoding = null, VoiceSettings voiceSettings = null, OutputFormat outputFormat = OutputFormat.MP3_44100_128, int? optimizeStreamingLatency = null, Model model = null)
public TextToSpeechRequest(
Voice voice,
string text,
Encoding encoding = null,
VoiceSettings voiceSettings = null,
OutputFormat outputFormat = OutputFormat.MP3_44100_128,
int? optimizeStreamingLatency = null,
Model model = null,
string previousText = null)
{
if (string.IsNullOrWhiteSpace(text))
{
Expand All @@ -40,6 +48,7 @@ public TextToSpeechRequest(Voice voice, string text, Encoding encoding = null, V
Model = model ?? Models.Model.MultiLingualV2;
Voice = voice;
VoiceSettings = voiceSettings ?? voice.Settings ?? throw new ArgumentNullException(nameof(voiceSettings));
PreviousText = previousText;
OutputFormat = outputFormat;
OptimizeStreamingLatency = optimizeStreamingLatency;
}
Expand All @@ -60,6 +69,10 @@ public TextToSpeechRequest(Voice voice, string text, Encoding encoding = null, V
[JsonProperty("voice_settings")]
public VoiceSettings VoiceSettings { get; internal set; }

[Preserve]
[JsonProperty("previous_text")]
public string PreviousText { get; }

[Preserve]
[JsonIgnore]
public OutputFormat OutputFormat { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public async Task Test_02_Dubbing_Url()
{
Assert.NotNull(ElevenLabsClient.DubbingEndpoint);

var request = new DubbingRequest(new Uri("https://youtu.be/Zo5-rhYOlNk"), "ja", "en", 1, true);
var request = new DubbingRequest(new Uri("https://youtu.be/Zo5-rhYOlNk"), "ja", "en", 1, watermark: true, dropBackgroundAudio: true);
var metadata = await ElevenLabsClient.DubbingEndpoint.DubAsync(request, progress: new Progress<DubbingProjectMetadata>(metadata =>
{
switch (metadata.Status)
Expand Down
2 changes: 1 addition & 1 deletion ElevenLabs/Packages/com.rest.elevenlabs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "ElevenLabs",
"description": "A non-official Eleven Labs voice synthesis RESTful client.",
"keywords": [],
"version": "3.3.0",
"version": "3.3.1",
"unity": "2021.3",
"documentationUrl": "https://github.com/RageAgainstThePixel/com.rest.elevenlabs#documentation",
"changelogUrl": "https://github.com/RageAgainstThePixel/com.rest.elevenlabs/releases",
Expand Down
2 changes: 1 addition & 1 deletion ElevenLabs/Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"com.unity.ide.rider": "3.0.31",
"com.unity.ide.visualstudio": "2.0.22",
"com.unity.test-framework": "1.3.5",
"com.utilities.buildpipeline": "1.4.7"
"com.utilities.buildpipeline": "1.5.0"
},
"scopedRegistries": [
{
Expand Down

0 comments on commit e7f175b

Please sign in to comment.