mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-14 09:03:16 +00:00
fix(transcription): read the frame count once to keep the type gate flat
This commit is contained in:
parent
b6d25f2752
commit
54dcd9230f
2 changed files with 6 additions and 4 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue