Skip to content

Commit

Permalink
com.rest.elevenlabs 3.4.1 (#106)
Browse files Browse the repository at this point in the history
- updated text to speech demo
  • Loading branch information
StephenHodgson authored Nov 25, 2024
1 parent fd14bc5 commit 6131c3d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 10 additions & 9 deletions Samples~/TextToSpeech/TextToSpeechDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using ElevenLabs.TextToSpeech;
using ElevenLabs.Voices;
using System;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -33,7 +33,7 @@ public class TextToSpeechDemo : MonoBehaviour
[SerializeField]
private AudioSource audioSource;

private readonly Queue<float> sampleQueue = new();
private readonly ConcurrentQueue<float> sampleQueue = new();

#if !UNITY_2022_3_OR_NEWER
private readonly CancellationTokenSource lifetimeCts = new();
Expand Down Expand Up @@ -78,9 +78,9 @@ private async void Start()
sampleQueue.Enqueue(sample);
}
}, cancellationToken: destroyCancellationToken);
audioSource.clip = voiceClip.AudioClip;
await new WaitUntil(() => sampleQueue.Count == 0 || destroyCancellationToken.IsCancellationRequested);
await new WaitUntil(() => sampleQueue.IsEmpty || destroyCancellationToken.IsCancellationRequested);
destroyCancellationToken.ThrowIfCancellationRequested();
audioSource.clip = voiceClip.AudioClip;

if (debug)
{
Expand All @@ -103,15 +103,16 @@ private async void Start()

private void OnAudioFilterRead(float[] data, int channels)
{
if (sampleQueue.Count <= 0) { return; }
if (sampleQueue.IsEmpty) { return; }

for (var i = 0; i < data.Length; i += channels)
{
var sample = sampleQueue.Dequeue();

for (var j = 0; j < channels; j++)
if (sampleQueue.TryDequeue(out var sample))
{
data[i + j] = sample;
for (var j = 0; j < channels; j++)
{
data[i + j] = sample;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion 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.4.0",
"version": "3.4.1",
"unity": "2021.3",
"documentationUrl": "https://github.com/RageAgainstThePixel/com.rest.elevenlabs#documentation",
"changelogUrl": "https://github.com/RageAgainstThePixel/com.rest.elevenlabs/releases",
Expand Down

0 comments on commit 6131c3d

Please sign in to comment.