Skip to content

Commit

Permalink
updated unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenHodgson committed Nov 15, 2023
1 parent 1c33db5 commit b76a8ae
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
31 changes: 17 additions & 14 deletions ElevenLabs-DotNet-Tests/Test_Fixture_03_TextToSpeechEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

Expand All @@ -16,30 +17,32 @@ public async Task Test_01_TextToSpeech()
var voice = (await ElevenLabsClient.VoicesEndpoint.GetAllVoicesAsync()).FirstOrDefault();
Assert.NotNull(voice);
var defaultVoiceSettings = await ElevenLabsClient.VoicesEndpoint.GetDefaultVoiceSettingsAsync();
var clipPath = await ElevenLabsClient.TextToSpeechEndpoint.TextToSpeechAsync("The quick brown fox jumps over the lazy dog.", voice, defaultVoiceSettings);
Assert.NotNull(clipPath);
Console.WriteLine(clipPath);
var voiceClip = await ElevenLabsClient.TextToSpeechEndpoint.TextToSpeechAsync("The quick brown fox jumps over the lazy dog.", voice, defaultVoiceSettings);
Assert.NotNull(voiceClip);
Console.WriteLine(voiceClip);
}

[Test]
public async Task Test_02_TextToSpeechPartial()
public async Task Test_02_StreamTextToSpeech()
{
Assert.NotNull(ElevenLabsClient.TextToSpeechEndpoint);
var voice = (await ElevenLabsClient.VoicesEndpoint.GetAllVoicesAsync()).FirstOrDefault();
Assert.NotNull(voice);
bool callbackCalled = false;
var partialClips = new Queue<VoiceClip>();
var defaultVoiceSettings = await ElevenLabsClient.VoicesEndpoint.GetDefaultVoiceSettingsAsync();
var clipPath = await ElevenLabsClient.TextToSpeechEndpoint.TextToSpeechAsync("The quick brown fox jumps over the lazy dog.", voice, defaultVoiceSettings,
partialClipCallback: (partialClip) =>
var voiceClip = await ElevenLabsClient.TextToSpeechEndpoint.TextToSpeechAsync("The quick brown fox jumps over the lazy dog.", voice, defaultVoiceSettings,

partialClipCallback: async partialClip =>
{
callbackCalled = true;
return null;
Assert.IsNotNull(partialClip);
partialClips.Enqueue(partialClip);
await Task.CompletedTask;
});

Assert.NotNull(clipPath);
Assert.IsTrue(callbackCalled);
Console.WriteLine(clipPath);

Assert.NotNull(partialClips);
Assert.IsNotEmpty(partialClips);
Assert.NotNull(voiceClip);
Console.WriteLine(voiceClip.Id);
}
}
}
12 changes: 7 additions & 5 deletions ElevenLabs-DotNet/TextToSpeech/TextToSpeechEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@ public async Task<VoiceClip> TextToSpeechAsync(string text, Voice voice, VoiceSe
{
parameters.Add(OptimizeStreamingLatencyParameter, optimizeStreamingLatency.ToString());
}
var postRequest = new HttpRequestMessage(HttpMethod.Post, GetUrl($"/{voice.Id}{(partialClipCallback == null ? string.Empty : "/stream")}", parameters))
{
Content = payload,
};
var response = await Api.Client.SendAsync(postRequest, partialClipCallback == null ? HttpCompletionOption.ResponseContentRead : HttpCompletionOption.ResponseHeadersRead, cancellationToken);

using var postRequest = new HttpRequestMessage(HttpMethod.Post, GetUrl($"/{voice.Id}{(partialClipCallback == null ? string.Empty : "/stream")}", parameters));
postRequest.Content = payload;
var requestOption = partialClipCallback == null
? HttpCompletionOption.ResponseContentRead
: HttpCompletionOption.ResponseHeadersRead;
var response = await Api.Client.SendAsync(postRequest, requestOption, cancellationToken);
await response.CheckResponseAsync(cancellationToken).ConfigureAwait(false);
var clipId = response.Headers.GetValues(HistoryItemId).FirstOrDefault();

Expand Down

0 comments on commit b76a8ae

Please sign in to comment.