Skip to content

FIX Avoid blocking WAV reads in realtime target - #2305

Open
romanlutz wants to merge 1 commit into
microsoft:mainfrom
romanlutz:romanlutz-daily-reference-maintainability-audit
Open

FIX Avoid blocking WAV reads in realtime target#2305
romanlutz wants to merge 1 commit into
microsoft:mainfrom
romanlutz:romanlutz-daily-reference-maintainability-audit

Conversation

@romanlutz

Copy link
Copy Markdown
Contributor

Description

RealtimeTarget.send_audio_async performed synchronous wave.open() and readframes() calls on the event loop, which could stall concurrent realtime audio requests.

This moves WAV loading into a synchronous helper executed with asyncio.to_thread. The audio bytes and WAV metadata continue through the existing API payload and output-saving path unchanged.

Tests and Documentation

  • Added a unit test that verifies WAV loading is offloaded and preserves the base64 payload, channel count, sample width, and frame rate.
  • tests/unit/prompt_target/target/test_realtime_target.py: 46 passed.
  • Ruff, formatting, async-suffix, type checking, pre-commit hooks, and git diff --check passed.
  • Documentation is not applicable because this is an internal event-loop reliability fix with no API or behavior change.

Move WAV loading to asyncio.to_thread so realtime audio sends do not block the event loop. Add coverage for the offloaded read and preserved payload metadata.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 1c85c49c-2d6c-4050-b3e3-ce085c97c5ec
raise NotImplementedError("RealtimeTarget uses receive_events for message construction")

@staticmethod
def _read_wav_file(filename: str) -> tuple[bytes, int, int, int]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: do we want docstring for this?

@jsong468 jsong468 self-assigned this Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants