diff --git a/litellm/litellm_core_utils/audio_utils/utils.py b/litellm/litellm_core_utils/audio_utils/utils.py index ea594bd9a73..dee5f0cc0e7 100644 --- a/litellm/litellm_core_utils/audio_utils/utils.py +++ b/litellm/litellm_core_utils/audio_utils/utils.py @@ -343,9 +343,10 @@ def calculate_request_duration(file: FileTypes) -> float | None: # Extract duration using soundfile file_object: Final = io.BytesIO(file_content) with sf.SoundFile(file_object) as audio: - if len(audio) >= LIBSNDFILE_UNKNOWN_FRAME_COUNT: + frames: Final = len(audio) + if frames >= LIBSNDFILE_UNKNOWN_FRAME_COUNT: return None - duration: Final = len(audio) / audio.samplerate + duration: Final = frames / audio.samplerate return duration except Exception: diff --git a/litellm/proxy/pass_through_endpoints/llm_provider_handlers/transcribe_passthrough_logging_handler.py b/litellm/proxy/pass_through_endpoints/llm_provider_handlers/transcribe_passthrough_logging_handler.py index 40aba7e4df6..ec189b83195 100644 --- a/litellm/proxy/pass_through_endpoints/llm_provider_handlers/transcribe_passthrough_logging_handler.py +++ b/litellm/proxy/pass_through_endpoints/llm_provider_handlers/transcribe_passthrough_logging_handler.py @@ -524,9 +524,10 @@ async def write_media_within_limit(response: httpx.Response, media_file: IO[byte def media_file_seconds(path: Path) -> float | None: try: with soundfile.SoundFile(str(path)) as audio: - if len(audio) >= LIBSNDFILE_UNKNOWN_FRAME_COUNT: + frames: Final = len(audio) + if frames >= LIBSNDFILE_UNKNOWN_FRAME_COUNT: return None - return len(audio) / audio.samplerate + return frames / audio.samplerate except (RuntimeError, ValueError, OSError) as e: verbose_proxy_logger.warning("Transcribe media could not be decoded for its duration: %s", e) return None