diff --git a/litellm/litellm_core_utils/audio_utils/utils.py b/litellm/litellm_core_utils/audio_utils/utils.py index ea1a5a4d4dc..ea594bd9a73 100644 --- a/litellm/litellm_core_utils/audio_utils/utils.py +++ b/litellm/litellm_core_utils/audio_utils/utils.py @@ -34,10 +34,6 @@ def normalized_audio_duration_seconds(value: object) -> float | None: LIBSNDFILE_UNKNOWN_FRAME_COUNT: Final = 2**63 - 1 -def soundfile_duration_seconds(frames: int, samplerate: int) -> float | None: - return None if frames >= LIBSNDFILE_UNKNOWN_FRAME_COUNT else frames / samplerate - - @dataclass class ProcessedAudioFile: """ @@ -347,7 +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: - return soundfile_duration_seconds(len(audio), audio.samplerate) + if len(audio) >= LIBSNDFILE_UNKNOWN_FRAME_COUNT: + return None + duration: Final = len(audio) / audio.samplerate + return duration except Exception: # Silently fail if duration extraction fails 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 d86903127bb..40aba7e4df6 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 @@ -29,7 +29,7 @@ from litellm.constants import ( TRANSCRIBE_MEDIA_FETCH_ATTEMPTS, TRANSCRIBE_MEDIA_LAST_MODIFIED_TOLERANCE_SECONDS, ) -from litellm.litellm_core_utils.audio_utils.utils import soundfile_duration_seconds +from litellm.litellm_core_utils.audio_utils.utils import LIBSNDFILE_UNKNOWN_FRAME_COUNT from litellm.litellm_core_utils.aws_partition import get_aws_dns_suffix from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj from litellm.litellm_core_utils.litellm_logging import ( @@ -524,7 +524,9 @@ 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: - return soundfile_duration_seconds(len(audio), audio.samplerate) + if len(audio) >= LIBSNDFILE_UNKNOWN_FRAME_COUNT: + return None + return len(audio) / 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