Add voice assistant audio settings (#556)

This commit is contained in:
Jesse Hills 2023-09-27 08:34:07 +13:00 committed by GitHub
parent b8b0c37d05
commit a17dc3c380
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 101 additions and 68 deletions

View File

@ -1438,6 +1438,12 @@ message SubscribeVoiceAssistantRequest {
bool subscribe = 1;
}
message VoiceAssistantAudioSettings {
uint32 noise_suppression_level = 1;
uint32 auto_gain = 2;
float volume_multiplier = 3;
}
message VoiceAssistantRequest {
option (id) = 90;
option (source) = SOURCE_SERVER;
@ -1445,7 +1451,8 @@ message VoiceAssistantRequest {
bool start = 1;
string conversation_id = 2;
int32 flags = 3;
uint32 flags = 3;
VoiceAssistantAudioSettings audio_settings = 4;
}
message VoiceAssistantResponse {

File diff suppressed because one or more lines are too long

View File

@ -94,6 +94,7 @@ from .api_pb2 import ( # type: ignore
SwitchStateResponse,
TextSensorStateResponse,
UnsubscribeBluetoothLEAdvertisementsRequest,
VoiceAssistantAudioSettings,
VoiceAssistantEventData,
VoiceAssistantEventResponse,
VoiceAssistantRequest,
@ -1354,7 +1355,9 @@ class APIClient:
async def subscribe_voice_assistant(
self,
handle_start: Callable[[str, int], Coroutine[Any, Any, int | None]],
handle_start: Callable[
[str, int, VoiceAssistantAudioSettings], Coroutine[Any, Any, int | None]
],
handle_stop: Callable[[], Coroutine[Any, Any, None]],
) -> Callable[[], None]:
"""Subscribes to voice assistant messages from the device.
@ -1383,7 +1386,9 @@ class APIClient:
command = VoiceAssistantCommand.from_pb(msg)
if command.start:
start_task = asyncio.create_task(
handle_start(command.conversation_id, command.flags)
handle_start(
command.conversation_id, command.flags, command.audio_settings
)
)
start_task.add_done_callback(_started)
# We hold a reference to the start_task in unsub function

View File

@ -1073,11 +1073,22 @@ class VoiceAssistantCommandFlag(enum.IntFlag):
USE_WAKE_WORD = 1 << 1
@_frozen_dataclass_decorator
class VoiceAssistantAudioSettings(APIModelBase):
noise_suppression_level: int = 0
auto_gain: int = 0
volume_multiplier: float = 1.0
@_frozen_dataclass_decorator
class VoiceAssistantCommand(APIModelBase):
start: bool = False
conversation_id: str = ""
flags: int = False
audio_settings: VoiceAssistantAudioSettings = converter_field(
default=VoiceAssistantAudioSettings(),
converter=VoiceAssistantAudioSettings.from_pb,
)
class LogLevel(APIIntEnum):