mirror of
https://github.com/esphome/aioesphomeapi.git
synced 2024-11-15 10:55:13 +01:00
Add VoiceAssistantAudio message
This commit is contained in:
parent
15d1949654
commit
6435be617d
@ -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
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user