elevenlabs / elevenlabs-python

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

SSML not recognized when streaming. #352

Open EllenOrange opened 2 months ago

EllenOrange commented 2 months ago

Hi folks,

As the title suggests, when using streaming with the 1.7.0 version of the python interface, it seems like ssml isn't recognized; instead it's read as part of the narration. Perhaps I'm not setting some needed switch in client.generate, but I've combed the api docs and can't find a solution.

Here's a minimum reproducible example:

from elevenlabs.client import ElevenLabs
from elevenlabs import play, stream

ssml_test_string1 = 'This is the beginning of a beautiful '
ssml_test_string2 = '<break time="1.0s"/> friendship.'

client = ElevenLabs()

audio = client.generate(
  text=ssml_test_string1 + ssml_test_string2,
  voice="Rachel",
  model="eleven_turbo_v2"
)
play(audio)

def text_stream():
    yield ssml_test_string1
    yield ssml_test_string2

audio_stream = client.generate(
    text=text_stream(),
    voice="Rachel",
    model="eleven_turbo_v2",
    stream=True
)

stream(audio_stream)