Skip to content

Commit a82f8ce

Browse files
committed
Expose VoiceSessionKey in VoiceSession
1 parent 41aa9c4 commit a82f8ce

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

ucapi/api.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@
4646
AudioConfiguration,
4747
)
4848
from .voice_assistant import Commands as VaCommands
49-
from .voice_stream import VoiceEndReason, VoiceSession, VoiceStreamHandler
49+
from .voice_stream import (
50+
VoiceEndReason,
51+
VoiceSession,
52+
VoiceSessionKey,
53+
VoiceStreamHandler,
54+
)
5055

5156
try:
5257
from ._version import version as __version__
@@ -57,10 +62,6 @@
5762
_LOG.setLevel(logging.DEBUG)
5863

5964

60-
VoiceSessionKey = tuple[Any, int]
61-
"""Tuple of (websocket, session_id)"""
62-
63-
6465
@dataclass(slots=True)
6566
class _VoiceSessionContext:
6667
session: VoiceSession

ucapi/voice_stream.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@
1414
import logging
1515
from asyncio import AbstractEventLoop
1616
from enum import Enum, auto
17-
from typing import AsyncIterator, Awaitable, Callable, Optional
17+
from typing import Any, AsyncIterator, Awaitable, Callable, Optional
1818

1919
from .api_definitions import AssistantEvent
2020
from .voice_assistant import AudioConfiguration
2121

2222
_LOG = logging.getLogger(__name__)
2323

2424

25+
VoiceSessionKey = tuple[Any, int]
26+
"""Tuple of (websocket, session_id)"""
27+
2528
VoiceStreamHandler = Callable[["VoiceSession"], Optional[Awaitable[None]]]
2629
"""Public type alias for the handler callable.
2730
@@ -113,6 +116,11 @@ def __aiter__(self) -> AsyncIterator[bytes]:
113116
"""Return an async iterator over audio frames."""
114117
return self.frames()
115118

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+
116124
async def send_event(self, event: AssistantEvent):
117125
"""Send an assistant event to the session initiator client."""
118126
await self._api.send_assistant_event(self._websocket, event)

0 commit comments

Comments
 (0)