lugia19 / elevenlabslib

Full python wrapper for the elevenlabs API.
MIT License
150 stars 27 forks source link

generate_and_stream_audio audio glitches and other issues #10

Closed KrogFrog closed 1 year ago

KrogFrog commented 1 year ago

When I use the generate_and_stream_audio call I almost always get "Output underflow: increase blocksize" error. (See traceback below.) I never get this error when using the non-streaming call "generate_and_play_audio".

I note that in the ElevenLabsVoice.py file, there is the following comment just above the area where the error seems to be triggered. May be related?

        # Since I can't find any way to get the buffer size from soundfile,
        # we will just assume the first read operation gives back a complete chunk
        # and use that to check later reads. This SHOULD be accurate. Hopefully.
        # Maybe there's like a weird edge case or something, hopefully not.

Using Python 3.11.2

The text I'm passing in to generate_and_stream_audio is often fairly short. Here is one example text string that generated the error: "Well, I am an AI, so I do not really have feelings, but thanks for asking. How about you?"

Also, I'm using version 0.4.0 of ElevenLabsLib (did a pip update just today, March 29th)


Error messages to console

We're not at the end. Wait for more data. ERROR:root:Output underflow: increase blocksize? Traceback (most recent call last): File "", line 1, in File "C:\Users\JeffR\OneDrive\JeffR\CodeProjects\Celeste\ElevenLapb_ModuleTest.py", line 39, in speakMsg voice.generate_and_stream_audio(text, stability=0.2) File "C:\Users\JeffR\AppData\Local\Programs\Python\Python311\Lib\site-packages\elevenlabslib\ElevenLabsVoice.py", line 220, in generate_and_stream_audio self._q.put(data, timeout=timeout) File "C:\Users\JeffR\AppData\Local\Programs\Python\Python311\Lib\queue.py", line 148, in put raise Full queue.Full

lugia19 commented 1 year ago

Yeah, it's something I need to look into, alongside the other issues with the streaming function. I likely won't have the time to do so for a week or so, so I'll keep the issue open for now.

In the meantime, if you don't need the like, half a second less of latency that the streaming functionality gives you, just use the normal one.

KrogFrog commented 1 year ago

OK, and thanks. I appreciate the response, and your work in developing the library. It has been very helpful.

lugia19 commented 1 year ago

As a small update, I haven't forgotten about this issue, it's just been excruciatingly difficult to fix.

It seems that the bug that causes the weird cutting out (and by extension the underflow) is probably in libsndfile, which, well, means it's going to take a while to get fixed. I'm considering adding a separate function that uses ffmpeg for the time being, but I'm still not sure.

lugia19 commented 1 year ago

After a fair amount of back and forth with the soundfile dev, I narrowed down the issue and was able to design a workaround which stops the weird audio glitches completely (hopefully also a more "proper" fix in soundfile later down the line).

I'll include it in an update either today or tomorrow, I'd like to clean up the streaming functionality a bit while I'm at it.

lugia19 commented 1 year ago

New version released, everything should be fixed.

KrogFrog commented 1 year ago

Thanks!
I just verified the fix. I upgraded to version 0.4.3, and I'm no longer getting the "underflow: increase blocksize" error when calling the generate_and_stream_audio function. Thanks for your hard work.