Skip to content

fix: guard RTF division in debug log for zero-duration audio - #668

Open
Archlie wants to merge 2 commits into
speaches-ai:masterfrom
Archlie:fix/zero-duration-rtf-division
Open

fix: guard RTF division in debug log for zero-duration audio#668
Archlie wants to merge 2 commits into
speaches-ai:masterfrom
Archlie:fix/zero-duration-rtf-division

Conversation

@Archlie

@Archlie Archlie commented Aug 9, 2026

Copy link
Copy Markdown

Fixes #667

Problem

Uploading a well-formed but zero-duration audio file (e.g. a header-only WAV with 0 samples) to POST /v1/audio/transcriptions returns HTTP 500 instead of the pre-0.9.0 clean 200 with empty text.

Root cause: the RTF debug log line in audio_file_dependency uses an eager f-string:

logger.debug(f"Decoded {audio.duration}s of audio in {elapsed:.5f}s (RTF: {elapsed / audio.duration})")

Because f-strings evaluate eagerly, elapsed / audio.duration runs even when debug logging is disabled (log_level does not mitigate it). audio.duration == 0 is reachable: a well-formed container that decodes to an empty sample array makes decode_audio() succeed (so the av.error.* handlers don't fire) and returns a zero-length result. The ZeroDivisionError is then caught by the generic except Exception handler, which turns it into a 500.

Fix

Guard the division with audio.duration > 0. Zero-duration uploads now flow through to the normal empty-transcription path, restoring the pre-rc behavior; normal files still log RTF as before.

Test

Added tests/dependencies_test.py with a mock-based regression test that feeds a zero-duration sample array through audio_file_dependency and asserts no crash and duration == 0.0.

Archlie added 2 commits August 9, 2026 10:51
The debug log line in audio_file_dependency eagerly evaluates
elapsed / audio.duration inside an f-string, so a well-formed but
zero-duration audio file (empty sample array) raised ZeroDivisionError,
turning a 200 into a 500 even when debug logging was disabled.

Guard the division with audio.duration > 0 and log RTF as n/a for
zero-duration files, restoring the pre-0.9.0 behavior of returning
an empty transcription.
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.

ZeroDivisionError (500) on zero-duration audio: RTF debug f-string divides by audio.duration

1 participant