Audio operator overview

Updated at:

This topic describes the operator list, limits, usage, audio data forms, and an example audio processing pipeline of the audio operators in the Python DataFrame API.

Limits

  • Available only in Realtime Compute Engine VVR 11.8 and later.

  • All audio operators are imported from pyflink.multimodal.operators.

  • Audio processing operators depend on the soundfile library, which is built into the engine.

Operator list

Click an operator name to jump to the operator details on the corresponding page.

Category

Operator

Description

Decoding

audio_decode

Decodes DataType.binary(), a URI, or AUDIO_CLIP_REF_TYPE into float32 PCM AUDIO_WAVEFORM_TYPE. Suitable for unifying inputs before resampling, channel conversion, speech detection, splitting, or recognition. For example, convert MP3, WAV, or FLAC files into sample data that downstream waveform operators can process directly.

audio_encode

Encodes float32 PCM AUDIO_WAVEFORM_TYPE into WAV, FLAC, AIFF, MP3, or OGG bytes. Suitable for persisting or transmitting waveforms after transformation, concatenation, or splitting, or for handing off to systems that accept only encoded files. For example, save a standardized 16 kHz mono waveform as WAV.

Format conversion

audio_convert_format

Decodes the input first, and then re-encodes it into new bytes in the target format. Suitable when downstream systems require a specific container or encoding format. For example, normalize audio from various sources into WAV, FLAC, or other formats.

audio_standardize

Converts channels first and then resamples, unifying the audio waveform to the specified sample rate and number of channels. Suitable for normalizing inputs from different sources before ASR, VAD, or model inference.

audio_resample

Changes the sample rate of the audio waveform by using soxr HQ while preserving the original number of channels. Suitable when downstream systems require a specific sample rate but the original channel layout must be kept. For example, convert a 48 kHz stereo recording to 16 kHz stereo.

audio_concat

Concatenates multiple audio waveforms that share the same sample rate, number of channels, and sample format, in array order. Suitable for reassembling split segments or merging results processed in parts. For example, restore consecutive segments after parallel denoising into a single audio clip.

Validity check

is_valid_audio

Checks, at the specified validation level, whether encoded audio can be processed further by probing the media header or fully decoding it, and returns a Boolean result. Suitable for external audio ingestion, bulk backfill, or pre-ASR quality checks. For example, use metadata for low-cost coarse screening first, and then use decode to exclude truncated audio, empty audio, and data that exceeds the decoding size limit.

Property extraction

audio_metadata

Reads audio metadata such as sample rate, number of channels, number of frames, duration, format, codec, bitrate, and object size. Suitable for audio inventory, quality statistics, and routing by attribute. For example, select a preprocessing pipeline by sample rate, or identify abnormal data sources by format.

audio_duration

Calculates and returns the duration of audio in seconds. Suitable for bucketing audio by length, estimating processing costs, or planning splitting strategies. For example, send extra-long recordings to fixed-duration splitting, and pass short recordings directly to ASR.

Data filtering

audio_duration_filter

Checks whether the audio duration falls within the specified closed interval. You can set the lower bound only, the upper bound only, or both. Suitable for filtering out samples that are too short or too long before model inference or training. For example, exclude invalid recordings shorter than 1 second, or block audio that exceeds the model input limit.

audio_size_filter

Checks by byte size whether a DataType.binary() or URI audio object falls within the specified closed interval, without reading the media content. Suitable for controlling resource consumption before downloading, decoding, or sending data to downstream services. For example, block oversized objects in advance to reduce network and memory pressure.

Audio detection

audio_silence_detection

Detects low-amplitude silence intervals in the audio waveform.

audio_detect_speech

Detects speech activity intervals in the audio waveform by using WebRTC VAD.

Audio splitting

audio_split_by_duration

Splits audio sequentially by the specified fixed duration and outputs actual audio waveforms or segment references based on segment_type. Suitable for processing long audio that exceeds the per-request input limit of downstream systems. For example, split a one-hour recording into 30-second segments and feed them to ASR in parallel. The last segment can be shorter.

audio_split_by_timestamp

Splits audio by the start and end time ranges provided by the caller, and outputs audio waveforms or segment references in the original order. Suitable when subtitles, logs, meeting minutes, or manually annotated timelines are already available. For example, extract the corresponding audio by subtitle timestamps, or locate utterance segments by meeting minutes.

audio_split_by_speech

Based on existing speech activity ranges, expands boundaries, merges intervals, filters out short segments, and splits long segments, and then outputs audio waveforms or segment references. Suitable for processing calls, interviews, or podcasts that contain a large amount of silence. For example, use it together with audio_detect_speech to skip blanks and generate only voice segments suitable for ASR.

Usage

Basic invocation

Operators without dedicated configuration parameters can be applied directly to DataFrame columns.

from pyflink.dataframe import col
from pyflink.multimodal.operators import audio_metadata

result = df.with_column(
    "metadata",
    audio_metadata(col("audio_bytes"))
)

Invocation with parameters

You can configure parameters for an operator while passing in columns.

from pyflink.multimodal.operators import audio_decode

result = df.with_column(
    "waveform",
    audio_decode(
        col("audio_bytes"),
        on_error="null"
    )
)

You can also create a configured operator first and then apply it to one or more columns:

decode = audio_decode(on_error="null")

result = df.with_column(
    "waveform",
    decode(col("audio_bytes"))
)

Data types

Audio data forms

Data form

DataFrame type

Description

Encoded audio

DataType.binary()

Encoded audio bytes in formats such as WAV, FLAC, OGG, AIFF, or MP3.

Audio URI

DataType.string()

A path accessible by Flink FileSystem or an object storage URI.

Audio segment reference

AUDIO_CLIP_REF_TYPE

Stores the URI and a time range without copying the audio content.

Decoded waveform

AUDIO_WAVEFORM_TYPE

Stores the float32 PCM tensor, sample rate, number of channels, and source information.

Audio metadata

AUDIO_METADATA_TYPE

The property structure returned by audio_metadata.

Audio segment reference (AUDIO_CLIP_REF_TYPE)

DataType.struct({
    "uri": DataType.string(),
    "start_time_ms": DataType.int64(),
    "end_time_ms": DataType.int64()
})

Audio segments use the half-open time interval [start_time_ms, end_time_ms). None as the start or end represents the beginning or end of the file, respectively.

Decoded audio waveform (AUDIO_WAVEFORM_TYPE)

DataType.struct({
    "data": DataType.tensor("float32"),
    "sample_rate": DataType.int32(),
    "channels": DataType.int32(),
    "frames": DataType.int64(),
    "sample_format": DataType.string(),
    "layout": DataType.string(),
    "duration_ms": DataType.int64(),
    "source_uri": DataType.string(),
    "start_time_ms": DataType.int64(),
    "end_time_ms": DataType.int64(),
})

data stores a variable-shape float32 PCM tensor.

Python operators expose it as a NumPy array with the shape (frames, channels).

Audio metadata (AUDIO_METADATA_TYPE)

DataType.struct({
    "sample_rate": DataType.int32(),
    "channels": DataType.int32(),
    "frames": DataType.int64(),
    "duration_ms": DataType.int64(),
    "format": DataType.string(),
    "codec": DataType.string(),
    "bit_rate": DataType.int64(),
    "size": DataType.int64()
})

Field

Description

sample_rate

Sample rate, in Hz.

channels

Number of channels.

frames

Number of sample frames per channel.

duration_ms

Duration, in milliseconds.

format

Container format.

codec

Short codec name.

bit_rate

The encoded bitrate. If it cannot be determined, the value is None.

size

Encoded object size, in bytes. For waveform inputs, the value is None.

Audio time ranges

The silence and speech detection operators return:

DataType.list(
    DataType.struct({
        "start_ms": DataType.int64(),
        "end_ms": DataType.int64(),
        "duration_ms": DataType.int64()
    })
)

Timestamp splitting and speech splitting also accept ranges without duration_ms:

DataType.list(
    DataType.struct({
        "start_ms": DataType.int64(),
        "end_ms": DataType.int64()
    })
)

Time ranges use the half-open interval [start_ms, end_ms). Time in detection and splitting parameters is usually in milliseconds. audio_duration and audio_duration_filter use seconds. When materializing waveform segments, millisecond boundaries are converted to sample frames and rounded, so non-frame-aligned boundaries may introduce a small timing offset.

Null and error handling

Scenario

Configuration

Raise an exception when decoding fails

audio_decode(on_error="raise"). This is the default Python behavior.

Return a null value when decoding fails

audio_decode(on_error="null").

Probe only the container or file header

is_valid_audio(validation="metadata").

Fully decode and validate the media content

is_valid_audio(validation="decode").

Notes:

  • on_error="null" handles only recognizable media data errors.

  • Inaccessible URIs, invalid audio segment references, wrong input types, missing dependencies, and invalid parameters still raise exceptions.

  • audio_duration_filter returns False for null values, corrupted inputs, or unknown durations.

  • audio_size_filter checks only the byte length or object size, so corrupted content that meets the size requirement may still return True.

Complete pipeline example

Consider preprocessing customer-service recordings: the DataFrame stores the original recording bytes, and downstream systems need to split them into segments by speech intervals for ASR.

The following pipeline sequentially decodes the audio, standardizes it to 16 kHz mono, detects speech activity intervals, splits it into independent segments, and computes the duration of each segment.

from pyflink.dataframe import col
from pyflink.multimodal.operators import (
    audio_decode,
    audio_detect_speech,
    audio_duration,
    audio_split_by_speech,
    audio_standardize,
)

# Decode -> standardize to 16 kHz mono -> filter out nulls -> detect speech intervals
prepared = (
    df.with_column(
        "waveform",
        audio_standardize(
            audio_decode(
                col("audio_bytes"),
                on_error="null",
            ),
            sample_rate=16000,
            channels=1,
        ),
    )
    .filter(col("waveform").is_not_null)
    .with_column(
        "speech_ranges",
        audio_detect_speech(
            col("waveform"),
            aggressiveness=2,
            frame_ms=30,
            min_speech_ms=100,
            merge_gap_ms=50,
            max_segments=1024,
        ),
    )
)

# Split into separate clips by speech interval
segments = prepared.join_lateral(
    audio_split_by_speech(
        col("waveform"),
        col("speech_ranges"),
        segment_type="audio"
    ).alias("segment")
)

# Compute the duration of each clip
result = (
    segments
    .with_column(
        "segment_duration_seconds",
        audio_duration(col("segment"))
    )
)

References