Audio splitting
Audio splitting functions split the input audio into segments by fixed duration, specified timestamps, or voice activity ranges. They are suitable for long-audio segmentation and pre-splitting before speech recognition.
Description
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 splitting functions return a table with a single
segmentcolumn, one segment per row. Audio segments use a half-open interval[start_ms, end_ms). -
The
segment_typeMust be a constant'audio'or'ref', which also determines the input requirement and the static type of the returned column:-
'audio'requires a decoded audio waveform and returns a materialized waveform. -
'ref'requires a URI or audio segment reference and returns a reference containing only the URI and time bounds.
-
-
Audio splitting functions are table functions (TableFunction) and must be invoked via
LATERAL TABLE.
Function summary
|
Function |
Whether ref mode opens the source file |
Description |
|
(probes duration) |
Splits audio into segments of the specified fixed duration in order, based on |
|
|
(fully lazy) |
Splits audio using caller-provided start and end time ranges and outputs audio waveforms or segment references in the original order.Suitable for scenarios where subtitles, logs, meeting minutes, or manually annotated timelines are already available., for example extracting audio by subtitle timing or locating spoken segments from meeting minutes. |
|
|
(reads metadata) |
Based on existing voice activity ranges, this function pads, merges, filters short segments, and splits long ones, then outputs audio waveforms or segment references.Suitable for handling calls, interviews, or podcasts with lots of silence., for example combined with |
AUDIO_SPLIT_BY_DURATION
Split audio into segments of a fixed duration.
AUDIO_SPLIT_BY_DURATION(
audio_input,
segment_duration_ms
[, segment_type
[, max_segments]]
)
|
Parameter |
Type |
Default |
Description |
|
audio_input |
audio waveform |
Required |
Audio to split.input |
|
segment_duration_ms |
|
Required |
Target duration per segment, in milliseconds. Must be greater than 0. |
|
segment_type |
|
|
outputmode: |
|
max_segments |
|
|
Maximum number of segments per input. Must be greater than 0. |
Returns: segment. segment_type 'audio', the static type is audio waveform ROW; 'ref', the static type is audio segment reference ROW.
Description:
-
'audio'mode requires the input to be a decoded audio waveform and materializes the samples of each segment. -
'ref'mode requires a URI or audio segment reference. The function probes the duration and clips against the actual duration and existing reference bounds, generating references only without copying audio content. -
The last segment may be shorter than
segment_duration_ms. -
When the required segment count exceeds
max_segments, an exception is raised rather than silently truncating. -
segment_type, defaults to'audio'. In that case, the input is treated as a waveform. If audio_input is a URI or an audio segment reference, you must explicitly pass 'ref'; otherwise a type-mismatch error occurs at runtime.
SELECT t.id, s.segment
FROM audio_waveforms AS t
CROSS JOIN LATERAL TABLE(
AUDIO_SPLIT_BY_DURATION(t.waveform, 30000, 'audio', 1024)
) AS s(segment);
SELECT t.id, s.segment
FROM audio_files AS t
CROSS JOIN LATERAL TABLE(
AUDIO_SPLIT_BY_DURATION(t.uri, 30000, 'ref', 1024)
) AS s(segment);
AUDIO_SPLIT_BY_TIMESTAMP
Split audio using caller-provided time ranges.
AUDIO_SPLIT_BY_TIMESTAMP(
audio_input,
timestamps
[, segment_type]
)
|
Parameter |
Type |
Default |
Description |
|
audio_input |
audio waveform |
Required |
Audio to split. |
|
timestamps |
range |
Required |
|
|
segment_type |
|
|
outputmode: |
Returns: segment. Return type segment_type.
range, end_ms must be greater than or equal to start_ms. In the three-field form, duration_ms is not used in computation; only start_ms and end_ms are used. If the input or timestamps is NULL, no rows are emitted.
-
'audio'mode clips ranges against the actual timeline of the waveform. Ranges that are entirely out of range or empty after clipping are dropped. -
'ref'mode is fully lazy for plain URIs: it does not open the file, does not verify that the URI exists, and does not clip against the actual audio duration. -
'ref'mode only clips existing audio segment references against their declared bounds, without validating whether the bounds exceed the actual file duration. -
Output order follows
timestampsinput,.
SELECT t.id, s.segment
FROM audio_files AS t
CROSS JOIN LATERAL TABLE(
AUDIO_SPLIT_BY_TIMESTAMP(
t.uri,
ARRAY[
ROW(CAST(1000 AS BIGINT), CAST(3500 AS BIGINT)),
ROW(CAST(5000 AS BIGINT), CAST(7000 AS BIGINT))
],
'ref'
)
) AS s(segment);
AUDIO_SPLIT_BY_SPEECH
Splits audio using upstream-generated voice activity ranges. This function does not perform speech detection itself; use AUDIO_DETECT_SPEECH output as speech_activity input.
SQL supports only the 2-, 3-, and 9-argument forms:
AUDIO_SPLIT_BY_SPEECH(audio_input, speech_activity)
AUDIO_SPLIT_BY_SPEECH(
audio_input,
speech_activity,
segment_type
)
AUDIO_SPLIT_BY_SPEECH(
audio_input,
speech_activity,
segment_type,
pre_padding_ms,
post_padding_ms,
merge_gap_ms,
min_segment_ms,
max_segment_ms,
max_segments
)
|
Parameter |
Type |
Default |
Description |
|
audio_input |
audio waveform |
Required |
Audio to split. |
|
speech_activity |
range |
Required |
Array of two-field or three-field time ranges. In the three-field form, |
|
segment_type |
|
|
outputmode: |
|
pre_padding_ms |
|
|
Padding to add before each segment. Must be greater than or equal to 0. |
|
post_padding_ms |
|
|
Padding to add after each segment. Must be greater than or equal to 0. |
|
merge_gap_ms |
|
|
Merges ranges whose gap is at most this value. Must be greater than or equal to 0. |
|
min_segment_ms |
|
|
Discards ranges shorter than this value. Must be greater than or equal to 0. |
|
max_segment_ms |
|
|
Ranges longer than this value are split into consecutive non-overlapping chunks of at most |
|
max_segments |
|
|
Maximum number of resulting segments. Must be greater than 0. |
Returns: segment. Return type segment_type.
To set any tuning parameter, you must specify all nine positional arguments at once; the four- to eight-argument forms cannot be used. When max_segment_ms is not enabled, use NULL directly.
The function processes speech ranges in the following order:
-
Adds padding before and after each range; the start is clamped to 0.
-
by start time.
-
Merges overlapping ranges as well as those whose gap is at most
merge_gap_msinterval. -
Drops ranges with non-positive duration and those shorter than
min_segment_msinterval. -
max_segment_ms. Long ranges are further split into consecutive chunks, each no longer than this value; the last chunk may be shorter. -
result
max_segments, an exception is raised. -
Clips against the waveform or audio object bounds and drops ranges that are entirely out of range.
and AUDIO_SPLIT_BY_TIMESTAMP(..., 'ref') differs: speech splitting 'ref' mode reads metadata to determine and clip against the actual audio duration. If the input or speech_activity NULL, no rows are emitted.
WITH detected AS (
SELECT
id,
waveform,
AUDIO_DETECT_SPEECH(waveform, 2, 30, 100, 50, 1024) AS speech_ranges
FROM audio_waveforms
)
SELECT t.id, s.segment
FROM detected AS t
CROSS JOIN LATERAL TABLE(
AUDIO_SPLIT_BY_SPEECH(
t.waveform,
t.speech_ranges,
'audio',
200,
200,
50,
100,
NULL,
1024
)
) AS s(segment);