in libs/libcommon/src/libcommon/viewer_utils/features.py [0:0]
def get_audio_file_extension(value: Any) -> Optional[str]:
if "path" in value and isinstance(value["path"], str):
# .split("::")[0] for chained URLs like zip://audio.wav::https://foo.bar/data.zip
# It might be "" for audio files downloaded from the Hub: make it None
audio_file_extension = os.path.splitext(value["path"].split("::")[0])[1] or None
elif ("path" in value and value["path"] is None) or "array" in value:
audio_file_extension = ".wav"
else:
raise ValueError(
"An audio sample should have 'path' and 'bytes' (or 'array' and 'sampling_rate') but got"
f" {', '.join(value)}."
)
return audio_file_extension