Skip to content

fix: validate audio sample rates - #6506

Closed
fallintoplace wants to merge 1 commit into
google:mainfrom
fallintoplace:fix/audio-sample-rate-validation
Closed

fix: validate audio sample rates#6506
fallintoplace wants to merge 1 commit into
google:mainfrom
fallintoplace:fix/audio-sample-rate-validation

Conversation

@fallintoplace

Copy link
Copy Markdown
Contributor

Summary

  • match rate only as a complete, case-insensitive MIME parameter
  • reject non-positive source and destination sample rates before returning or resampling
  • cover zero-rate inputs, bitrate parameters, and uppercase RATE parameters

Why

parse_sample_rate previously treated rate= as an arbitrary substring, so parameters such as bitrate=128000 could be interpreted as sample rates. It also accepted zero, which could reach a division by zero in resample_pcm16. Direct calls with a zero destination rate had the same problem.

Rejecting invalid rates explicitly avoids silently producing incorrectly pitched or timed audio.

Validation

  • uv run pytest tests/unittests/evaluation/test_audio_utils.py -q
  • uv run pre-commit run --files src/google/adk/evaluation/_audio_utils.py tests/unittests/evaluation/test_audio_utils.py

@adk-bot adk-bot added the eval [Component] This issue is related to evaluation label Jul 29, 2026
copybara-service Bot pushed a commit that referenced this pull request Jul 30, 2026
Merge #6506

- match `rate` only as a complete, case-insensitive MIME parameter
- reject non-positive source and destination sample rates before returning or resampling
- cover zero-rate inputs, `bitrate` parameters, and uppercase `RATE` parameters

PiperOrigin-RevId: 956811306
@adk-bot

adk-bot commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Thank you @fallintoplace for your contribution! 🎉

Your changes have been successfully imported and merged via Copybara in commit d24c84c.

Closing this PR as the changes are now in the main branch.

@adk-bot adk-bot added the merged [Status] This PR is merged label Jul 30, 2026
@adk-bot adk-bot closed this Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

eval [Component] This issue is related to evaluation merged [Status] This PR is merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants