This commit is contained in:
Quan Kaiyi 2026-11-05 19:54:42 +00:00 • committed by GitHub
commit 4ce490b0d4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -13,7 +13,6 @@ from typing import IO, Final, Protocol, TypeAlias
from urllib.parse import quote
import httpx
import soundfile
from pydantic import ConfigDict, TypeAdapter, ValidationError
from typing_extensions import ReadOnly, TypedDict
@ -515,6 +514,17 @@ async def write_media_within_limit(response: httpx.Response, media_file: IO[byte
def media_file_seconds(path: Path) -> float | None:
try:
# soundfile is only needed to measure media duration and is declared in
# extras that are not installed on the default `/v1/messages` streaming
# path; import lazily so module import never fails without it.
import soundfile
except ModuleNotFoundError:
verbose_proxy_logger.warning(
"soundfile not installed; Transcribe media duration measurement is skipped (install the 'proxy' or 'stt-nvidia-riva' extra to enable it)"
)
return None
try:
with soundfile.SoundFile(str(path)) as audio:
return len(audio) / audio.samplerate