|
14 | 14 | import logging |
15 | 15 | from asyncio import AbstractEventLoop |
16 | 16 | from enum import Enum, auto |
17 | | -from typing import AsyncIterator, Awaitable, Callable, Optional |
| 17 | +from typing import Any, AsyncIterator, Awaitable, Callable, Optional |
18 | 18 |
|
19 | 19 | from .api_definitions import AssistantEvent |
20 | 20 | from .voice_assistant import AudioConfiguration |
21 | 21 |
|
22 | 22 | _LOG = logging.getLogger(__name__) |
23 | 23 |
|
24 | 24 |
|
| 25 | +VoiceSessionKey = tuple[Any, int] |
| 26 | +"""Tuple of (websocket, session_id)""" |
| 27 | + |
25 | 28 | VoiceStreamHandler = Callable[["VoiceSession"], Optional[Awaitable[None]]] |
26 | 29 | """Public type alias for the handler callable. |
27 | 30 |
|
@@ -113,6 +116,11 @@ def __aiter__(self) -> AsyncIterator[bytes]: |
113 | 116 | """Return an async iterator over audio frames.""" |
114 | 117 | return self.frames() |
115 | 118 |
|
| 119 | + @property |
| 120 | + def key(self) -> VoiceSessionKey: |
| 121 | + """Return the session key to uniquely identify a session.""" |
| 122 | + return self._websocket, self.session_id |
| 123 | + |
116 | 124 | async def send_event(self, event: AssistantEvent): |
117 | 125 | """Send an assistant event to the session initiator client.""" |
118 | 126 | await self._api.send_assistant_event(self._websocket, event) |
|
0 commit comments