RageAgainstThePixel / com.rest.elevenlabs

A non-official Eleven Labs voice synthesis client for Unity (UPM)
https://elevenlabs.io/?from=partnerbrown9849
MIT License
74 stars 9 forks source link

Application freezes on first voice request #66

Closed jeffries7 closed 7 months ago

jeffries7 commented 7 months ago

I think this is more of a question than a bug but we're seeing large spikes when processing text.

We're using the latest version of the SDK & Unity 2021.3.21f1. This is running on a Meta Quest 3 but we're also seeing this when running in the editor.

Pretty much all requests we make after the first one are absolutely fine but the first one freezes the application for a second or two.

I've taken a look at the samples but it has the same results.

Below is the code we've been using for a while.

    public void ExecuteTask(string answer)
    {
         if (_isReady)
             Execute(answer);
    }

    private async void Execute(string answer)
    {
        _isReady = false;

        var api = new ElevenLabsClient();

        var voice = await api.VoicesEndpoint.GetVoiceAsync(voiceData.DefaultVoice.ID);

        var voiceClip = await api.TextToSpeechEndpoint.TextToSpeechAsync(answer, voice, model: Model.EnglishTurboV2);

        if (_audioSource.isPlaying)
        {
            _audioSource.Stop();
        }

        onAudioProcessed?.Invoke();

        _audioSource.clip = voiceClip.AudioClip;
        _audioSource.Play();

        StartCoroutine(CheckAudio());
    }