agents icon indicating copy to clipboard operation
agents copied to clipboard

TTS Optimization to generate speech lazily

Open anlagbr opened this issue 1 year ago • 3 comments

Currently, all speech is generated sequentially. However, if the agent is interrupted mid-speech, some audio will not be played, and a significant cost will still be incurred (TTS is typically the most expensive component among STT, LLM, and TTS).

I propose generating speech in a more efficient manner. For instance, the initial speech segment could be generated immediately. Subsequently, there would be a 1.5-second delay (depending on the provider) before generating the next chunk of audio (1.5 delay before current speech ends) coinciding with the completion of the current segment. This approach aims to minimize wasted computational resources and expenditure.

I couldn't find an official API solution for this problem.

Thanks.

anlagbr avatar Jul 23 '25 13:07 anlagbr

this feature is included in agents 1.2.3, here is an example https://github.com/livekit/agents/blob/[email protected]/examples/voice_agents/tts_text_pacing.py

longcw avatar Aug 05 '25 02:08 longcw

@longcw Does it work with Elevenlabs TTS?

shivamkataria2000 avatar Aug 06 '25 09:08 shivamkataria2000

@longcw Does it work with Elevenlabs TTS?

for 11labs it needs a tts.StreamAdapter to make it work in non-streaming mode. 11labs also has the auto_mode that accepts full sentences in the stream, we can support it with streaming laterly.

longcw avatar Aug 06 '25 10:08 longcw