-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelevenlabs.py
31 lines (25 loc) · 1.06 KB
/
elevenlabs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from typing import Any, AsyncIterator, Callable, Iterator, Optional
from elevenlabs.client import ElevenLabs
async def eleven_stream(
sentences: AsyncIterator[str],
eleven_client: ElevenLabs,
voice: Optional[str] = "Jessica",
) -> AsyncIterator[Iterator[bytes]]:
"""An AsyncIterator wrapper for the 11Labs TTS generation stream.
Args:
sentences (AsyncIterator): A sentence AsyncIterator
eleven_client (ElevenLabs): The 11Labs third-party TTS client.
messages (dict, optional): The message history of the dialogue system.
Yields:
Iterator[bytes]: A bytes iterator for playing audio using 11Labs stream audio playing function.
"""
async for sentence in sentences:
if sentence:
audio_stream = eleven_client.generate(
text=sentence, stream=True, voice=voice
)
yield audio_stream