elevenlabs / elevenlabs-python

The official Python API for ElevenLabs Text to Speech.
https://elevenlabs.io/docs/api-reference/getting-started
MIT License
2.12k stars 240 forks source link

(feat): Support for text iterators in `AsyncElevenLabs` #358

Open BackSlasher opened 2 weeks ago

BackSlasher commented 2 weeks ago

Redo of #346

Why: Allowing the async client to utilize incoming text streams when generating voice. Very useful when feeding the realtime output of an LLM into the TTS.

Closes #344

What:

  1. Copied RealtimeTextToSpeechClient and text_chunker into AsyncRealtimeTextToSpeechClient and async_text_chunker Most of the logic is intact, aside from async stuff
  2. Added AsyncRealtimeTextToSpeechClient into AsyncElevenLabs just like RealtimeTextToSpeechClient is in ElevenLabs
  3. Added rudimentary testing

The code is basically a copy-paste of what I found in the repo. We can rewrite it to be more elegant, but I figured parity with the sync code is more important.