vocalstack 1.0.0a9__tar.gz → 1.0.0a10__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {vocalstack-1.0.0a9 → vocalstack-1.0.0a10}/PKG-INFO +1 -1
- {vocalstack-1.0.0a9 → vocalstack-1.0.0a10}/pyproject.toml +1 -1
- {vocalstack-1.0.0a9 → vocalstack-1.0.0a10}/src/vocalstack/__init__.py +1 -1
- {vocalstack-1.0.0a9 → vocalstack-1.0.0a10}/src/vocalstack/realtime.py +49 -2
- {vocalstack-1.0.0a9 → vocalstack-1.0.0a10}/.gitignore +0 -0
- {vocalstack-1.0.0a9 → vocalstack-1.0.0a10}/LICENSE +0 -0
- {vocalstack-1.0.0a9 → vocalstack-1.0.0a10}/README.md +0 -0
- {vocalstack-1.0.0a9 → vocalstack-1.0.0a10}/SKILL.md +0 -0
- {vocalstack-1.0.0a9 → vocalstack-1.0.0a10}/skills/vocalstack/SKILL.md +0 -0
- {vocalstack-1.0.0a9 → vocalstack-1.0.0a10}/src/vocalstack/_http.py +0 -0
- {vocalstack-1.0.0a9 → vocalstack-1.0.0a10}/src/vocalstack/_models.py +0 -0
- {vocalstack-1.0.0a9 → vocalstack-1.0.0a10}/src/vocalstack/client.py +0 -0
- {vocalstack-1.0.0a9 → vocalstack-1.0.0a10}/src/vocalstack/errors.py +0 -0
- {vocalstack-1.0.0a9 → vocalstack-1.0.0a10}/src/vocalstack/resources.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: vocalstack
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.0a10
|
|
4
4
|
Summary: VocalStack speech API SDK (asyncio): one client grouped by resource, typed models from the API contract, realtime WebSocket streaming.
|
|
5
5
|
Project-URL: Homepage, https://vocalstack.com
|
|
6
6
|
License-Expression: MIT
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "vocalstack"
|
|
7
|
-
version = "1.0.
|
|
7
|
+
version = "1.0.0a10"
|
|
8
8
|
description = "VocalStack speech API SDK (asyncio): one client grouped by resource, typed models from the API contract, realtime WebSocket streaming."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
@@ -54,7 +54,9 @@ def upgrade_refused(status: int, body: Optional[bytes]) -> VocalStackError:
|
|
|
54
54
|
|
|
55
55
|
|
|
56
56
|
RESTART_CLOSE = 1012
|
|
57
|
+
LOST_WAITS_S = [1.0, 2.0, 4.0, 8.0, 15.0, 15.0, 15.0, 15.0]
|
|
57
58
|
RESTART_TRIES = 3
|
|
59
|
+
STEADY_S = 30.0
|
|
58
60
|
MAX_PENDING_BYTES = 4 * 1024 * 1024
|
|
59
61
|
|
|
60
62
|
|
|
@@ -88,6 +90,7 @@ class RealtimeSession:
|
|
|
88
90
|
self._ready_deadline_s = ready_deadline_s
|
|
89
91
|
self._reconnecting = False
|
|
90
92
|
self._reconnects = 0
|
|
93
|
+
self._opened_at = time.monotonic()
|
|
91
94
|
self._pending: List[Union[str, bytes]] = []
|
|
92
95
|
self._pending_bytes = 0
|
|
93
96
|
|
|
@@ -127,7 +130,9 @@ class RealtimeSession:
|
|
|
127
130
|
try:
|
|
128
131
|
ws = await websockets.connect(stream_url, max_size=None, open_timeout=ready_deadline_s, close_timeout=2)
|
|
129
132
|
except websockets.InvalidStatus as e:
|
|
130
|
-
|
|
133
|
+
refused = upgrade_refused(e.response.status_code, e.response.body)
|
|
134
|
+
refused._answered = True
|
|
135
|
+
raise refused from e
|
|
131
136
|
except TimeoutError as e:
|
|
132
137
|
raise VocalStackError(
|
|
133
138
|
"capacity_exceeded", f"the upgrade was not answered within {ready_deadline_s}s", retryable=True
|
|
@@ -194,8 +199,12 @@ class RealtimeSession:
|
|
|
194
199
|
async def _reconnect(self) -> None:
|
|
195
200
|
"""The relay restarting: open the same ``stream_url`` again (1, 2,
|
|
196
201
|
4 s apart), send what waited, and go on as the same session. Out
|
|
197
|
-
of tries: ``engine_lost``.
|
|
202
|
+
of tries: ``engine_lost``. A socket that stayed open ``STEADY_S``
|
|
203
|
+
before the restart close starts the tries anew, so a long session
|
|
204
|
+
goes through any number of restarts."""
|
|
198
205
|
self._reconnecting = True
|
|
206
|
+
if time.monotonic() - self._opened_at >= STEADY_S:
|
|
207
|
+
self._reconnects = 0
|
|
199
208
|
try:
|
|
200
209
|
while self._reconnects < RESTART_TRIES and not self._closed and self._stream_url:
|
|
201
210
|
await asyncio.sleep(2 ** self._reconnects)
|
|
@@ -207,6 +216,7 @@ class RealtimeSession:
|
|
|
207
216
|
raise
|
|
208
217
|
continue
|
|
209
218
|
self._ws = ws
|
|
219
|
+
self._opened_at = time.monotonic()
|
|
210
220
|
self._reconnecting = False
|
|
211
221
|
waiting, self._pending, self._pending_bytes = self._pending, [], 0
|
|
212
222
|
for d in waiting:
|
|
@@ -216,6 +226,36 @@ class RealtimeSession:
|
|
|
216
226
|
finally:
|
|
217
227
|
self._reconnecting = False
|
|
218
228
|
|
|
229
|
+
async def _recover(self) -> None:
|
|
230
|
+
"""The socket dropped with no close frame (the server it was on
|
|
231
|
+
stopped answering): open the same ``stream_url`` again, ``LOST_WAITS_S``
|
|
232
|
+
apart, for as long as the server answers "try again" (a retryable
|
|
233
|
+
refusal of the upgrade), send what waited, and go on as the same
|
|
234
|
+
session. A refusal for good, no answer at all, or the last try
|
|
235
|
+
spent: ``engine_lost``, as before."""
|
|
236
|
+
self._reconnecting = True
|
|
237
|
+
try:
|
|
238
|
+
for wait in LOST_WAITS_S:
|
|
239
|
+
await asyncio.sleep(wait)
|
|
240
|
+
if self._closed or not self._stream_url:
|
|
241
|
+
break
|
|
242
|
+
try:
|
|
243
|
+
ws = await self._open_ready(self._stream_url, self._ready_deadline_s, self._on_frame)
|
|
244
|
+
except Exception as e:
|
|
245
|
+
if isinstance(e, VocalStackError) and e.retryable and getattr(e, "_answered", False):
|
|
246
|
+
continue
|
|
247
|
+
break
|
|
248
|
+
self._ws = ws
|
|
249
|
+
self._opened_at = time.monotonic()
|
|
250
|
+
self._reconnecting = False
|
|
251
|
+
waiting, self._pending, self._pending_bytes = self._pending, [], 0
|
|
252
|
+
for d in waiting:
|
|
253
|
+
await self._send(d)
|
|
254
|
+
return
|
|
255
|
+
raise engine_lost()
|
|
256
|
+
finally:
|
|
257
|
+
self._reconnecting = False
|
|
258
|
+
|
|
219
259
|
async def send_file(
|
|
220
260
|
self,
|
|
221
261
|
source: Union[str, bytes, bytearray, "os.PathLike[str]"],
|
|
@@ -314,6 +354,13 @@ class RealtimeSession:
|
|
|
314
354
|
self._error = err
|
|
315
355
|
raise
|
|
316
356
|
continue
|
|
357
|
+
if e.rcvd is None and time.monotonic() - self._opened_at >= STEADY_S:
|
|
358
|
+
try:
|
|
359
|
+
await self._recover()
|
|
360
|
+
except VocalStackError as err:
|
|
361
|
+
self._error = err
|
|
362
|
+
raise err from e
|
|
363
|
+
continue
|
|
317
364
|
self._error = engine_lost(e.rcvd.code if e.rcvd else None)
|
|
318
365
|
raise self._error from e
|
|
319
366
|
if isinstance(raw, bytes):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|