Audio properties and filtering

Updated at:

This topic describes the audio property and filtering functions: IS_VALID_AUDIO, AUDIO_METADATA, AUDIO_DURATION, AUDIO_DURATION_FILTER, and AUDIO_SIZE_FILTER.

The functions in this topic are provided by the Python multimodal function library (VVR 11.8+). Load the module at the beginning of the SQL job before use:

LOAD MODULE python;
USE MODULES python, core;

Audio property functions validate and read audio metadata; filter functions return BOOLEAN, which can be used directly in WHERE condition clauses.

Function summary

Function

Category

Description

IS_VALID_AUDIO

Determines whether an encoded audio object can be further processed by probing the media header or fully decoding it at the specified check level. Returns a boolean.Suitable for validating external audio ingestion, batch replay, or as an ASR pre-check., for example first use metadata for lightweight filtering, and decode Rules out truncated, empty audio and data whose decoded size exceeds the limit.

AUDIO_METADATA

Reads audio metadata such as sample rate, channel count, frame count, duration, format, codec, bitrate, and object size.Suitable for audio inventory, quality statistics, and routing by properties., for example choosing a preprocessing pipeline based on sample rate or identifying abnormal sources by format.

AUDIO_DURATION

Returns the audio duration in seconds.Suitable for bucketing by audio length, estimating processing cost, or planning split strategies., for example routing overly long recordings to fixed-length splitting and sending short recordings directly to ASR.

AUDIO_DURATION_FILTER

Checks whether the audio duration lies within the specified closed interval. You can set only a lower bound, only an upper bound, or both.Suitable for filtering too-short or too-long samples before model inference or training., for example excluding recordings shorter than 1 second or blocking audio exceeding the model input limit.

AUDIO_SIZE_FILTER

Checks the byte size of BYTES or a URI audio object against a specified closed interval, without reading the media content.Suitable for controlling resource consumption before download, decoding, or downstream service calls., for example filtering out oversized objects up front to reduce network and memory pressure.

Audio properties and filtering

IS_VALID_AUDIO

Validates whether an encoded audio can be read. This function does not accept decoded waveforms.

IS_VALID_AUDIO(audio_input [, validation])

type

defaultvalue

audio_input

BYTES, STRING or audio segment reference ROW

Required

Encoded audio bytes, a URI, or an audio segment reference.

validation

STRING NOT NULL

'metadata'

Validation mode:'metadata' probes only the container or file header;'decode' performs full decoding.

Return type: BOOLEAN NOT NULL.

  • Cases that return FALSE (can be used in WHERE clauses to filter dirty data):

    • If input is NULL

    • Recognizable media data errors such as byte-stream corruption, truncation, or unrecognized format.

  • Cases that raise exceptions and fail the job (preconditions must be satisfied outside the job):

    • URI cannot be accessed (path missing, permission denied, or network failure).

    • Invalid audio segment reference (out-of-bounds or malformed reference).

    • Missing dependency or a non-media internal error.

For URI or segment reference inputs, reachability must be ensured by the caller; do not rely on IS_VALID_AUDIO as a fallback filter.

-- Byte input: URI issues do not apply. Only media corruption is filtered
SELECT * FROM raw_audio WHERE IS_VALID_AUDIO(audio_bytes, 'decode');

-- URI input: An unreachable URI fails the job. It is not filtered out
SELECT * FROM audio_files WHERE IS_VALID_AUDIO(uri, 'decode');
Note

The internal decoding limit for decode mode is fixed at 1 GiB, matching the default max_decoded_bytes of AUDIO_DECODE. It cannot be adjusted via parameters yet. Valid audio whose PCM decoded size exceeds 1 GiB is judged FALSE.

AUDIO_METADATA

Reads metadata from encoded audio or a waveform.

AUDIO_METADATA(audio_input)

type

defaultvalue

audio_input

BYTES, STRING, an audio segment reference ROW or audio waveform ROW

Required

Audio to read metadata from.

Return type: audio metadata ROW.

  • If input is NULL. Returns the value below when the encoded audio is corrupt: NULL. Exceptions such as URI access failure, invalid waveforms, or dependency errors are still thrown.

  • For an audio segment reference, frames and duration_ms is clipped to the referenced interval; size still reflects the size of the full encoded object.

  • For an audio waveform, format, codec, bit_rate and size NULL.

  • This function has no on_error.

-- Recommended: Use an explicit single call to avoid relying on optimizer behavior
SELECT
 meta.sample_rate,
 meta.duration_ms
FROM (
 SELECT AUDIO_METADATA(audio_bytes) AS meta FROM raw_audio
);

-- Or use a CTE:
WITH decoded AS (
 SELECT AUDIO_METADATA(audio_bytes) AS meta FROM raw_audio
)
SELECT meta.sample_rate, meta.duration_ms FROM decoded;

AUDIO_DURATION

Reads the audio duration.

AUDIO_DURATION(audio_input)

type

defaultvalue

audio_input

BYTES, STRING, an audio segment reference ROW or audio waveform ROW

Required

Audio to read duration from.

Return type: DOUBLE. Unit: seconds.

first obtains the millisecond duration and then divides by 1000.0. If input is NULL. Returns the value below when encoded data is corrupt or the duration cannot be determined: NULL. Non-media data errors such as URI access failure are still thrown. This function has no on_error.

SELECT AUDIO_DURATION(audio_bytes) AS duration_seconds
FROM raw_audio;

AUDIO_DURATION_FILTER

Checks whether the audio duration is within a specified closed interval.

AUDIO_DURATION_FILTER(audio_input, min_seconds [, max_seconds])

type

defaultvalue

audio_input

BYTES, STRING, an audio segment reference ROW or audio waveform ROW

Required

Audio to filter.

min_seconds

DOUBLE

Required

Minimum duration. Bound is inclusive and must be greater than or equal to 0. In the three-argument form, may be NULL.

max_seconds

DOUBLE

NULL

Maximum duration. Bound is inclusive and must be greater than or equal to 0.

Return type: BOOLEAN NOT NULL.

At least one bound must be non- NULL. When both are specified, max_seconds Must be greater than or equal to min_seconds. If input is NULL. Returns the value below when the encoded audio is corrupt or the duration is unknown: FALSE. When only an upper bound is set, use NULL:

SELECT *
FROM raw_audio
WHERE AUDIO_DURATION_FILTER(
 audio_bytes,
 CAST(NULL AS DOUBLE),
 30.0
);

AUDIO_SIZE_FILTER

Checks whether the byte length of an encoded audio object is within the specified closed interval. This function does not read or decode media content, so corrupt data whose size still matches the interval returns TRUE.

AUDIO_SIZE_FILTER(audio_input, min_bytes [, max_bytes])

type

defaultvalue

audio_input

BYTES or STRING

Required

Encoded audio bytes or a URI. Segment references and audio waveforms are not supported.

min_bytes

INT or BIGINT

Required

Minimum byte count. Bound is inclusive and must be greater than or equal to 0. In the three-argument form, may be NULL.

max_bytes

INT or BIGINT

NULL

Maximum byte count. Bound is inclusive and must be greater than or equal to 0.

Return type: BOOLEAN NOT NULL.

At least one bound must be non- NULL. The upper bound must not be smaller than the lower bound. Byte inputs use the length directly; URI inputs read the file size. If the input is NULL, returns FALSE, the function returns an error when the file is missing, the URI is inaccessible, or the URI points to a directory.

SELECT *
FROM raw_audio
WHERE AUDIO_SIZE_FILTER(
 audio_bytes,
 NULL,
 10485760
);