elevenlabs / elevenlabs-python

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

Streaming Input Example Does not Work until whole Input is Send #395

Open gwpl opened 1 month ago

gwpl commented 1 month ago

Description

I've been sending one line at a time ending with punctuation, either from other program generating stream of text , or just by hand from terminal, and it looks like no audio is happening in speakers until whole text is read (or timeout encountered), even if each line ends with punctuaction!

Code example

#!/usr/bin/env python3

from elevenlabs.client import ElevenLabs
from elevenlabs import stream

client = ElevenLabs(
#  api_key="YOUR_API_KEY", # Defaults to ELEVEN_API_KEY
)

import sys

def generate_text_line_yielder(file_object):
    def text_stream():
        for line in file_object:
            yield line
    return text_stream

text_stream = generate_text_line_yielder(sys.stdin)

#voice_model="eleven_multilingual_v2"
voice_model="eleven_turbo_v2_5"
audio_stream = client.generate(
    text=text_stream(),
    voice="Brian",
    model=voice_model,
    stream=True
)

stream(audio_stream)

Additional context

I wonder if iit's related to #344 and could be fixed by PR referenced there or if it's other issue.