Add VoiceAssistantAudio message

This commit is contained in:
Michael Hansen 2024-03-19 17:05:48 -05:00 committed by Jesse Hills
parent 15d1949654
commit 6435be617d
No known key found for this signature in database
GPG Key ID: BEAAE804EFD8E83A
3 changed files with 123 additions and 77 deletions

View File

@ -1515,6 +1515,14 @@ message VoiceAssistantEventResponse {
repeated VoiceAssistantEventData data = 2; repeated VoiceAssistantEventData data = 2;
} }
message VoiceAssistantAudio {
option (id) = 106;
option (source) = SOURCE_BOTH;
option (ifdef) = "USE_VOICE_ASSISTANT";
bytes data = 1;
}
// ==================== ALARM CONTROL PANEL ==================== // ==================== ALARM CONTROL PANEL ====================
enum AlarmControlPanelState { enum AlarmControlPanelState {
ALARM_STATE_DISARMED = 0; ALARM_STATE_DISARMED = 0;

File diff suppressed because one or more lines are too long

View File

@ -71,6 +71,7 @@ from .api_pb2 import ( # type: ignore
VoiceAssistantEventResponse, VoiceAssistantEventResponse,
VoiceAssistantRequest, VoiceAssistantRequest,
VoiceAssistantResponse, VoiceAssistantResponse,
VoiceAssistantAudio,
) )
from .client_callbacks import ( from .client_callbacks import (
on_bluetooth_connections_free_response, on_bluetooth_connections_free_response,
@ -1296,6 +1297,31 @@ class APIClient:
return unsub return unsub
def subscribe_voice_assistant_audio(
self,
handle_audio: Callable[
[VoiceAssistantAudio],
Coroutine[Any, Any, None],
],
) -> Callable[[], None]:
connection = self._get_connection()
audio_task: asyncio.Task[int | None] | None = None
def _on_voice_assistant_audio(msg: VoiceAssistantRequest) -> None:
nonlocal audio_task
audio = VoiceAssistantAudio.from_pb(msg)
self._create_background_task(handle_audio(audio))
connection.send_message(SubscribeVoiceAssistantRequest(subscribe=True))
remove_callback = connection.add_message_callback(
_on_voice_assistant_audio, (VoiceAssistantAudio,)
)
return remove_callback
def _create_background_task(self, coro: Coroutine[Any, Any, None]) -> None: def _create_background_task(self, coro: Coroutine[Any, Any, None]) -> None:
"""Create a background task and add it to the background tasks set.""" """Create a background task and add it to the background tasks set."""
task = asyncio.create_task(coro) task = asyncio.create_task(coro)