Add opt-in local audio devices to the voice helper (#43079)

## What changed

- Add `openDevices` and `setAudioControls` to the helper protocol. Open the default microphone and speaker after runtime initialization and transport negotiation, initially muted and suppressed.
- Use CPAL on macOS, GNU Linux, and MSVC Windows, with native audio dependencies confined to `codex-voice-host`. Add ALSA development dependencies to Linux CI.
- Pack callback samples into preallocated, bounded queues and service devices every 5 ms. Reject incompatible callback configurations, invalidate queued audio on control transitions, and reject capture backlog after unmute using device timestamps.
- Handle recoverable stream underruns and overruns without terminating the helper; terminate on device failure, active audio queue overflow, or stale queued audio.

Device opening only establishes local device readiness. Capture and rendered audio references are drained locally; encoding, decoding, and peer audio are not connected by this change.

## Testing

Add unit tests for mute boundaries, stale playback invalidation, sample bounds, partial-block packing and timestamps, callback size and timing limits, startup silence, queue overflow, and recoverable stream errors.

GitOrigin-RevId: 108aea3d411ef6c12908fe5fb67aaf9cddf4475f
This commit is contained in:
Benjamin Carlsson authored and copyberry committed 2026-09-05 19:11:52 +00:00
1 parent 51c97f3a67
commit 19b62211d9
14 files changed
+1318 -9

No files matched your search

+1
View File
@@ -3,6 +3,7 @@ mod message_reader;
mod protocol;
pub use client::VoiceHost;
pub use protocol::AudioControls;
pub use protocol::MAX_FRAME_BYTES;
pub use protocol::Message;
pub use protocol::RUNTIME_ENVIRONMENT;
+11
View File
@@ -8,6 +8,13 @@ use serde::Serialize;
pub const MAX_FRAME_BYTES: usize = 128 * 1024;
#[derive(Debug, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct AudioControls {
pub microphone_muted: bool,
pub speaker_suppressed: bool,
}
/// SDP contains ICE credentials. Bound it at construction and never expose it in diagnostics.
#[derive(Deserialize, PartialEq, Serialize)]
#[serde(try_from = "String")]
@@ -66,6 +73,10 @@ pub enum Message {
Offer { sdp: SessionDescription },
ApplyAnswer { sdp: SessionDescription },
TransportReady {},
OpenDevices {},
DevicesOpened {},
SetAudioControls { controls: AudioControls },
AudioControlsApplied {},
Close {},
Closed {},
}