Skip to content

Conversation

@ruskaruma
Copy link
Contributor

Summary

In #2010 we noticed realtime PCM16 audio was being reported in microseconds. The root cause was our fallback branch in calculate_audio_length_ms, which divided by 24 * 2 and then by 1000, effectively treating every byte as a millisecond. I normalized the format first, split g711 from PCM handling, and introduced explicit constants for the sample rate and sample width so PCM16 now returns the true millisecond duration. This also covers empty buffers and any future lowercase/uppercase format variants.

To keep coverage honest, I updated the realtime playback tracker tests to assert against the corrected math using pytest.approx, and refreshed the manual tracker test to reflect the new millisecond totals.

Test plan

  • uv run pytest tests/realtime/test_playback_tracker_manual_unit.py tests/realtime/test_playback_tracker.py tests/realtime/test_openai_realtime.py
  • uv run pytest

Fixes #2010.

@ruskaruma
Copy link
Contributor Author

Greetings @seratch, I’ve opened this PR referencing issue #2010. Please review the patch and let me know if it correctly addresses the problem or if any adjustments are needed.

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.

Typo in realtime code in calculate_audio_length_ms function

1 participant