in api_inference_community/validation.py [0:0]
def normalize_payload_audio(bpayload: bytes, sampling_rate: int) -> Tuple[Any, Dict]:
if os.path.isfile(bpayload) and bpayload.startswith(DATA_PREFIX.encode("utf-8")):
# XXX:
# This is necessary for batch jobs where the datasets can contain
# filenames instead of the raw data.
# We attempt to sanitize this roughly, by checking it lives on the data
# path (hardcoded in the deployment and in all the dockerfiles)
# We also attempt to prevent opening files that are not obviously
# audio files, to prevent opening stuff like model weights.
filename, ext = os.path.splitext(bpayload)
if ext.decode("utf-8")[1:] in AUDIO:
with open(bpayload, "rb") as f:
bpayload = f.read()
inputs = ffmpeg_read(bpayload, sampling_rate)
if len(inputs.shape) > 1:
# ogg can take dual channel input -> take only first input channel in this case
inputs = inputs[:, 0]
return inputs, {}