@@ -87,6 +87,7 @@ class Voice:
8787
8888API_BASE_URL_V1 = "https://api.elevenlabs.io/v1"
8989AUTHORIZATION_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
107109class 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