Omit undersized WAV output from Code Mode (#41934)

## Why

Audio models cannot reliably encode tool-generated clips shorter than 25 ms.

## What changed

- Measure the available audio frames in base64-encoded PCM and IEEE float WAV outputs.
- Replace clips under 25 ms with explanatory text while preserving surrounding Code Mode output.
- Leave clips at or above the threshold and unrecognized audio formats unchanged.

## Testing

- Cover the duration boundary across multiple sample rates and all supported `audio()` input forms.
- Verify bounded and truncated WAV chunks, output after `yield_control()`, and end-to-end mixed text and audio output.

GitOrigin-RevId: 342b4bdbc65db4238580f9cdc372763c2576eca5
This commit is contained in:
Jennifer Zhao authored and copyberry committed 2026-08-31 23:36:04 +00:00
1 parent a62ff9a5d4
commit 981d6b652b
8 files changed
+326

No files matched your search

@@ -1189,6 +1189,9 @@ audio({
);
}
#[path = "service_audio_tests.rs"]
mod audio_tests;
#[tokio::test]
async fn audio_helper_rejects_non_data_urls() {
for source in [