Audio operator overview
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
soundfilelibrary, 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 |
Decodes |
|
|
Encodes float32 PCM |
||
|
Format conversion |
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. |
|
|
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. |
||
|
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. |
||
|
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 |
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 |
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. |
|
|
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 |
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. |
|
|
Checks by byte size whether a |
||
|
Audio detection |
Detects low-amplitude silence intervals in the audio waveform. |
|
|
Detects speech activity intervals in the audio waveform by using WebRTC VAD. |
||
|
Audio splitting |
Splits audio sequentially by the specified fixed duration and outputs actual audio waveforms or segment references based on |
|
|
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. |
||
|
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 |
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 |
|
Encoded audio bytes in formats such as WAV, FLAC, OGG, AIFF, or MP3. |
|
Audio URI |
|
A path accessible by Flink FileSystem or an object storage URI. |
|
Audio segment reference |
|
Stores the URI and a time range without copying the audio content. |
|
Decoded waveform |
|
Stores the float32 PCM tensor, sample rate, number of channels, and source information. |
|
Audio metadata |
|
The property structure returned by |
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, in Hz. |
|
|
Number of channels. |
|
|
Number of sample frames per channel. |
|
|
Duration, in milliseconds. |
|
|
Container format. |
|
|
Short codec name. |
|
|
The encoded bitrate. If it cannot be determined, the value is |
|
|
Encoded object size, in bytes. For waveform inputs, the value is |
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 |
|
|
Return a null value when decoding fails |
|
|
Probe only the container or file header |
|
|
Fully decode and validate the media content |
|
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_filterreturnsFalsefor null values, corrupted inputs, or unknown durations. -
audio_size_filterchecks only the byte length or object size, so corrupted content that meets the size requirement may still returnTrue.
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"))
)
)