Skip to content

Commit

Permalink
added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenHodgson committed Nov 24, 2024
1 parent a354f84 commit eda0bdb
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ internal Alignment(
[Preserve]
public static implicit operator TimestampedTranscriptCharacter[](Alignment alignment)
{
if (alignment == null) { return null; }
var characters = alignment.Characters;
var startTimes = alignment.StartTimes;
var endTimes = alignment.EndTimes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ void ProcessPartialResponse(string line)
return;
}

var timestampedTranscriptCharacters = (TimestampedTranscriptCharacter[])partialResponse.Alignment;
var timestampedTranscriptCharacters = (TimestampedTranscriptCharacter[])partialResponse.Alignment ?? Array.Empty<TimestampedTranscriptCharacter>();
partialClipCallback.Invoke(Tuple.Create(audioClip, timestampedTranscriptCharacters));
accumulatedPCMData.AddRange(partialClipData);
accumulatedTranscriptData.AddRange(timestampedTranscriptCharacters);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -40,5 +41,58 @@ public async Task Test_02_StreamTextToSpeech()
Assert.IsNotNull(voiceClip.AudioClip);
Debug.Log(voiceClip.Id);
}

[Test]
public async Task Test_03_TextToSpeech_Transcription()
{
Assert.NotNull(ElevenLabsClient.TextToSpeechEndpoint);
var voice = Voices.Voice.Adam;
Assert.NotNull(voice);
var defaultVoiceSettings = await ElevenLabsClient.VoicesEndpoint.GetDefaultVoiceSettingsAsync();
var voiceClip = await ElevenLabsClient.TextToSpeechEndpoint.TextToSpeechWithTimestampsAsync("The quick brown fox jumps over the lazy dog.", voice, defaultVoiceSettings);
Assert.NotNull(voiceClip);
Assert.NotNull(voiceClip.AudioClip);
Debug.Log(voiceClip.Id);
Assert.NotNull(voiceClip.TimestampedTranscriptCharacters);
Assert.IsNotEmpty(voiceClip.TimestampedTranscriptCharacters);
Debug.Log("| Character | Start Time | End Time |");
Debug.Log("| --------- | ---------- | -------- |");
foreach (var character in voiceClip.TimestampedTranscriptCharacters)
{
Debug.Log($"| {character.Character} | {character.StartTime} | {character.EndTime} |");
}
}

[Test]
public async Task Test_04_StreamTextToSpeech_Transcription()
{
Assert.NotNull(ElevenLabsClient.TextToSpeechEndpoint);
var voice = Voices.Voice.Adam;
Assert.NotNull(voice);
var defaultVoiceSettings = await ElevenLabsClient.VoicesEndpoint.GetDefaultVoiceSettingsAsync();
var partialClips = new Queue<AudioClip>();
var characters = new Queue<TimestampedTranscriptCharacter>();
Debug.Log("| Character | Start Time | End Time |");
Debug.Log("| --------- | ---------- | -------- |");
var voiceClip = await ElevenLabsClient.TextToSpeechEndpoint.StreamTextToSpeechWithTimestampsAsync("The quick brown fox jumps over the lazy dog.", voice,
callback =>
{
var (partialClip, chars) = callback;
partialClips.Enqueue(partialClip);
foreach (var character in chars)
{
characters.Enqueue(character);
Debug.Log($"| {character.Character} | {character.StartTime} | {character.EndTime} |");
}
},
defaultVoiceSettings);
Assert.NotNull(partialClips);
Assert.NotNull(partialClips);
Assert.IsNotEmpty(partialClips);
Assert.NotNull(voiceClip);
Assert.IsNotNull(voiceClip.AudioClip);
Debug.Log(voiceClip.Id);
Assert.AreEqual(characters.ToArray(), voiceClip.TimestampedTranscriptCharacters);
}
}
}

0 comments on commit eda0bdb

Please sign in to comment.