Skip to content

Commit eaf112c

Browse files
authored
fix: increase elevenlabs websocket timeout (#1582)
1 parent ab79d28 commit eaf112c

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

.changeset/cold-walls-jam.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"livekit-plugins-deepgram": patch
3+
---
4+
5+
set mex session duration to 1 hour in deepgram connection pool

.changeset/large-ears-mate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"livekit-plugins-elevenlabs": patch
3+
---
4+
5+
increase elevenlabs websocket connection timeout to default 300 seconds

livekit-plugins/livekit-plugins-deepgram/livekit/plugins/deepgram/tts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def __init__(
8686
self._pool = utils.ConnectionPool[aiohttp.ClientWebSocketResponse](
8787
connect_cb=self._connect_ws,
8888
close_cb=self._close_ws,
89+
max_session_duration=3600, # 1 hour
8990
)
9091

9192
async def _connect_ws(self) -> aiohttp.ClientWebSocketResponse:

livekit-plugins/livekit-plugins-elevenlabs/livekit/plugins/elevenlabs/tts.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class Voice:
8787

8888
API_BASE_URL_V1 = "https://api.elevenlabs.io/v1"
8989
AUTHORIZATION_HEADER = "xi-api-key"
90+
WS_INACTIVITY_TIMEOUT = 300
9091

9192

9293
@dataclass
@@ -102,6 +103,7 @@ class _TTSOptions:
102103
word_tokenizer: tokenize.WordTokenizer
103104
chunk_length_schedule: list[int]
104105
enable_ssml_parsing: bool
106+
inactivity_timeout: int
105107

106108

107109
class TTS(tts.TTS):
@@ -114,6 +116,7 @@ def __init__(
114116
base_url: str | None = None,
115117
encoding: TTSEncoding = "mp3_22050_32",
116118
streaming_latency: int = 3,
119+
inactivity_timeout: int = WS_INACTIVITY_TIMEOUT,
117120
word_tokenizer: tokenize.WordTokenizer = tokenize.basic.WordTokenizer(
118121
ignore_punctuation=False # punctuation can help for intonation
119122
),
@@ -134,6 +137,7 @@ def __init__(
134137
base_url (str | None): Custom base URL for the API. Optional.
135138
encoding (TTSEncoding): Audio encoding format. Defaults to "mp3_22050_32".
136139
streaming_latency (int): Latency in seconds for streaming. Defaults to 3.
140+
inactivity_timeout (int): Inactivity timeout in seconds for the websocket connection. Defaults to 300.
137141
word_tokenizer (tokenize.WordTokenizer): Tokenizer for processing text. Defaults to basic WordTokenizer.
138142
enable_ssml_parsing (bool): Enable SSML parsing for input text. Defaults to False.
139143
chunk_length_schedule (list[int]): Schedule for chunk lengths, ranging from 50 to 500. Defaults to [80, 120, 200, 260].
@@ -173,6 +177,7 @@ def __init__(
173177
chunk_length_schedule=chunk_length_schedule,
174178
enable_ssml_parsing=enable_ssml_parsing,
175179
language=language,
180+
inactivity_timeout=inactivity_timeout,
176181
)
177182
self._session = http_session
178183
self._pool = utils.ConnectionPool[aiohttp.ClientWebSocketResponse](
@@ -581,10 +586,11 @@ def _stream_url(opts: _TTSOptions) -> str:
581586
latency = opts.streaming_latency
582587
enable_ssml = str(opts.enable_ssml_parsing).lower()
583588
language = opts.language
589+
inactivity_timeout = opts.inactivity_timeout
584590
url = (
585591
f"{base_url}/text-to-speech/{voice_id}/stream-input?"
586592
f"model_id={model_id}&output_format={output_format}&optimize_streaming_latency={latency}&"
587-
f"enable_ssml_parsing={enable_ssml}"
593+
f"enable_ssml_parsing={enable_ssml}&inactivity_timeout={inactivity_timeout}"
588594
)
589595
if language is not None:
590596
url += f"&language_code={language}"

0 commit comments

Comments
 (0)