Skip to content

Commit

Permalink
feat: add support for passing latency to generate_stream_input si…
Browse files Browse the repository at this point in the history
…milar to `generate_stream` (elevenlabs#116)

Co-authored-by: Flavio Schneider <flavio.schneider.97@gmail.com>
  • Loading branch information
ryanstout and flavioschneider authored Dec 8, 2023
1 parent d08ef67 commit 7d25b2e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion elevenlabs/api/tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def generate_stream_input(
model: Model,
api_key: Optional[str] = None,
output_format: TTS.OutputFormat = "mp3_44100_128",
latency: int = 1,
) -> Iterator[bytes]:
BOS = json.dumps(
dict(
Expand All @@ -103,7 +104,7 @@ def generate_stream_input(
EOS = json.dumps(dict(text=""))

with connect(
f"wss://api.elevenlabs.io/v1/text-to-speech/{voice.voice_id}/stream-input?model_id={model.model_id}&output_format={output_format}",
f"wss://api.elevenlabs.io/v1/text-to-speech/{voice.voice_id}/stream-input?model_id={model.model_id}&output_format={output_format}&optimize_streaming_latency={latency}",
additional_headers={
"xi-api-key": api_key or os.environ.get("ELEVEN_API_KEY")
},
Expand Down
2 changes: 1 addition & 1 deletion elevenlabs/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def generate(
text, voice, model, stream_chunk_size, api_key=api_key, latency=latency, output_format=output_format
) # noqa E501
elif isinstance(text, Iterator):
return TTS.generate_stream_input(text, voice, model, api_key=api_key, output_format=output_format)
return TTS.generate_stream_input(text, voice, model, api_key=api_key, output_format=output_format, latency=latency)
else:
assert isinstance(text, str)
return TTS.generate(text, voice, model, api_key=api_key, output_format=output_format)

0 comments on commit 7d25b2e

Please sign in to comment.