Extract Segment — User Guide

Precise audio segmentation: extracts defined time intervals from sound objects with multiple selection and processing options.

Author: Audio Tools Team Affiliation: Department of Music, Bar-Ilan University, Israel Version: 2.1 (2025) License: MIT License Repo: https://github.com/ShaiCohen-ops/Praat-plugin_AudioTools
Contents:

What this does

This script implements precise audio segmentation — extracting defined time intervals from sound objects with multiple selection and processing options. Key capabilities: (1) Multiple selection: Extract from multiple sound objects simultaneously. (2) Flexible time specification: Absolute times, percentages, or marker-based. (3) Overlap handling: Extract overlapping segments with fade options. (4) Batch processing: Process multiple intervals in one operation. Process copies selected time region from source sound, applies optional fade in/out, creates new sound object with extracted segment. Result: cleanly extracted audio segments ready for further analysis or composition.

Key Features:

What is audio segmentation? Traditional extraction: manual selection in waveform editor, copy-paste operations. Advanced segmentation: automated extraction of defined intervals with precise boundary control. Advantages: (1) Precision: Sample-accurate boundary definition. (2) Efficiency: Batch processing of multiple segments. (3) Consistency: Identical parameters across extractions. (4) Automation: Scriptable for large datasets. (5) Flexibility: Multiple time specification methods. Use cases: Phonetic analysis (extracting specific phones), music production (sampling), audio research (creating stimulus sets), sound design (isolating effects), podcast editing (removing sections), archival work (segmenting long recordings).

Technical Implementation: (1) Input validation: Check time boundaries against sound duration. (2) Time conversion: Convert percentage/marker inputs to absolute times. (3) Boundary alignment: Adjust to nearest zero-crossing if requested. (4) Extraction: Copy samples from start to end time. (5) Fade application: Apply cosine-shaped fades at boundaries. (6) Object creation: Create new Sound object with extracted samples. (7) Metadata handling: Copy relevant annotations if enabled. (8) Batch processing: Loop through multiple intervals/sounds. Key insight: Flexible time specification allows different workflow approaches (absolute times for precision, percentages for relative extraction, markers for annotation-based work).

Quick start

  1. In Praat, select one or more Sound objects.
  2. Run script…extract_segment.praat.
  3. Choose time specification mode: Absolute, Percentage, or Marker-based.
  4. Enter start time and end time (or percentages/markers).
  5. Set fade in and fade out durations (optional).
  6. Enable zero-crossing alignment to avoid clicks at boundaries.
  7. Choose output naming convention for extracted segments.
  8. Click OK — segments extracted, named per convention.
Quick tip: Start with absolute time mode for precise extraction — enter exact start/end times in seconds. Use percentage mode when you want segments relative to total duration (e.g., extract middle 50%). Enable zero-crossing alignment to avoid audible clicks at segment boundaries. Apply short fades (5-20 ms) for smoother transitions. For batch processing, use multiple time intervals separated by commas. Output naming supports placeholders like %original%, %index%, %start%, %end% for organized results. Extracted segments appear in Objects window with "_seg#_from_X_to_Y" suffix by default.
Important: VALIDATE TIMES — start time must be ≥ 0 and ≤ end time; end time must be ≤ sound duration. Negative times or times exceeding duration cause errors. Percentage mode: 0% = start of sound, 100% = end of sound. Marker-based extraction requires TextGrid with interval tiers. Fade durations should be ≤ segment duration (fade longer than segment creates constant fade). Zero-crossing alignment may shift boundaries slightly (up to ~0.5 ms). Multiple selection: all selected sounds processed with same time parameters (unless using sound-specific times). Large batch operations may take time — progress bar shows status. Extracted segments are NEW objects — original sounds remain unchanged.

Extraction Modes

Mode 1: Absolute Time Extraction

⏱️ Precise Time-Based Control

Specification: Start and end times in seconds

Parameters: Start time (s), End time (s)

Character: Absolute precision, independent of duration

Best for: Known time intervals, scripted extraction, research protocols

Example scenarios:

ScenarioStart TimeEnd TimeResult
Extract first second0.01.00.0–1.0 segment
Extract from 2.5–4.2s2.54.22.5–4.2 segment
Extract last 500msduration-0.5durationLast half-second
Multiple intervals0, 2, 41, 3, 5Three segments

Mode 2: Percentage-Based Extraction

📊 Relative Duration Control

Specification: Start and end percentages of total duration

Parameters: Start (%), End (%)

Character: Relative to sound length, adaptable

Best for: Variable-length sounds, proportional extraction

Example scenarios:

ScenarioStart %End %Result
Extract first half0500%–50% segment
Extract middle third33.3366.66Middle third
Extract last quarter75100Last quarter
Exclude first/last 10%1090Middle 80%

Mode 3: Marker-Based Extraction

📍 Annotation-Driven Control

Specification: Based on TextGrid interval boundaries

Parameters: Tier number, Interval label(s)

Character: Annotation-aware, semantic extraction

Best for: Phonetic analysis, labeled datasets, annotation workflows

Example scenarios:

ScenarioTierLabelResult
Extract all "s" sounds1 (phone)sAll /s/ segments
Extract vowel intervals2 (vowel)a, e, i, o, uAll vowel segments
Extract specific word3 (word)helloAll "hello" instances
Extract pause regions4 (pause)sil, spAll silence/pause regions

Parameters & Options

Core Parameters

ParameterTypeDefaultDescription
time_modeoptionAbsoluteTime specification method
start_timetext0.0Start time/percentage/marker
end_timetext1.0End time/percentage/marker
fade_inreal0.0Fade-in duration (seconds)
fade_outreal0.0Fade-out duration (seconds)
align_zerobooleanyesAlign to zero-crossings
preserve_annotationsbooleannoCopy TextGrid annotations
naming_conventiontext%original%_seg%index%Output naming pattern

Time Mode Specific Parameters

ModeParameterDefaultDescription
Absolutetimes_in_secondstrueInput in seconds
Percentageround_percentagestrueRound to nearest 0.1%
Markertextgrid_tier1TextGrid tier number
Markerinterval_labels*Labels to extract (* = all)

Advanced Parameters

ParameterDefaultDescription
buffer_before0.0Add buffer before segment (s)
buffer_after0.0Add buffer after segment (s)
min_duration0.0Minimum segment duration (s)
max_duration0.0Maximum segment duration (s)
overlap_actionskipHow to handle overlapping intervals

Advanced Features

Batch Processing

🔄 Multiple Interval Extraction

Feature: Extract multiple segments in one operation

Syntax: Comma-separated time pairs

Example: start_times = "0, 2, 4", end_times = "1, 3, 5"

Result: Three segments: 0-1s, 2-3s, 4-5s

Zero-Crossing Alignment

↕️ Click-Free Boundaries

Purpose: Avoid audible clicks at segment boundaries

Method: Adjust times to nearest zero-crossing point

Effect: Smoother transitions, especially with no fade

Trade-off: Slight time shift (typically < 0.5ms)

Fade Application

Fade types:

Linear fade (default): amplitude_multiplier = t / fade_duration Cosine fade (smoother): amplitude_multiplier = 0.5 × (1 - cos(π × t / fade_duration)) Equal-power crossfade (for overlaps): left_gain = cos(π × t / (2 × fade_duration)) right_gain = sin(π × t / (2 × fade_duration)) Application: Fade in: start of segment (0→1 multiplier) Fade out: end of segment (1→0 multiplier) Crossfade: overlapping regions (smooth transition)

Overlap Handling Strategies

StrategyActionUse Case
skipSkip overlapping intervalsClean extraction, no duplicates
mergeMerge into single segmentContinuous regions
crossfadeApply crossfade in overlapSmooth transitions
separateExtract as separate segmentsAll instances needed

Naming Convention Placeholders

Available placeholders: %original% = original sound name %index% = segment number (1, 2, 3...) %start% = start time (formatted) %end% = end time (formatted) %duration% = segment duration %label% = interval label (marker mode) %tier% = tier number (marker mode) Examples: "%original%_seg%index%" → "sound1_seg1", "sound1_seg2" "%original%_%start%-%end%" → "sound1_0.5-1.2" "%label%_%index%" → "s_1", "s_2" (for /s/ segments)

Applications

Phonetic Research

Use case: Extract specific phone segments for analysis

Technique: Marker mode with phone-tier labels

Workflow:

  1. Annotate sounds in TextGrid (phone tier)
  2. Select sound + TextGrid objects
  3. Run extract with label filter (e.g., "s" for /s/ sounds)
  4. Extract all matching segments automatically

Music Sampling

Use case: Create sample library from recordings

Technique: Batch extraction with multiple intervals

Example: Extract individual drum hits, instrument notes, vocal phrases

Advanced: Use naming convention with musical properties (note, velocity, etc.)

Stimulus Preparation

Use case: Create experimental stimulus sets

Requirements: Precise durations, consistent boundaries

Technique: Absolute time mode with validation

Quality control: Zero-crossing alignment + short fades for smooth edges

Podcast/Audio Editing

Use case: Remove sections, extract highlights

Technique: Percentage mode for relative editing

Example: Remove first/last 10%, extract middle 80% as "highlight reel"

Efficiency: Batch process multiple episodes

Archival Segmentation

Use case: Split long recordings into manageable chunks

Technique: Regular interval extraction

Example: Extract 5-minute segments from 2-hour recording

Automation: Script to extract at fixed intervals

Practical Workflow Examples

🔬 Phonetic Analysis (Research)

Goal: Extract all instances of /t/ sounds for analysis

Settings:

  • Time mode: Marker-based
  • Tier: 1 (phone tier)
  • Labels: t, tʰ (aspirated t)
  • Buffer: 0.02 s before/after
  • Align zero: yes

Result: All /t/ segments extracted with 20ms context

🎵 Drum Sample Extraction (Music Production)

Goal: Create kick drum sample library

Settings:

  • Time mode: Absolute
  • Intervals: "0.5, 2.3, 4.1" to "0.8, 2.6, 4.4"
  • Fade out: 0.05 s
  • Naming: "kick_%index%"

Result: Three kick drum samples with short fade-out

🎤 Podcast Highlight Clips (Editing)

Goal: Extract best moments for promo

Settings:

  • Time mode: Percentage
  • Intervals: "15, 45, 70" to "25, 55, 80" (%)
  • Fade in/out: 0.1 s
  • Naming: "highlight_%index%"

Result: Three 10% segments from different parts

Troubleshooting Common Issues

Problem: "Time exceeds duration" error
Cause: End time > sound duration
Solution: Check time values, use duration-0.1 for end if needed
Problem: Extracted segment has clicks/pops
Cause: Boundaries not at zero-crossing
Solution: Enable zero-crossing alignment, add short fades
Problem: Marker mode not working
Cause: No TextGrid selected or tier doesn't exist
Solution: Select both Sound and TextGrid, check tier number
Problem: Batch extraction creates wrong number of files
Cause: Time list mismatch or overlap handling
Solution: Verify start/end lists have same count, check overlap_action

Technical Implementation Details

Time Boundary Processing

Zero-Crossing Alignment Algorithm

STEP 1: Find nearest zero-crossing forward from target time Search samples forward until sign change (positive→negative or negative→positive) If found within search window (default: 10ms), use that sample time STEP 2: If not found forward, search backward Search samples backward for sign change STEP 3: Apply to both start and end times start_aligned = nearest_zero_crossing(start_time) end_aligned = nearest_zero_crossing(end_time) STEP 4: Validate Ensure end_aligned > start_aligned Ensure both within sound boundaries Result: Boundaries at points where amplitude = 0 (or crossing through 0)

Fade Application Mathematics

Cosine Fade Calculation

For fade in (duration = fade_in): For each sample i in fade region (0 to N_fade): t = i / N_fade (normalized position, 0→1) gain = 0.5 × (1 - cos(π × t)) sample[i] = sample[i] × gain For fade out (duration = fade_out): For each sample i in fade region (0 to N_fade): t = i / N_fade (normalized position, 0→1) gain = 0.5 × (1 - cos(π × (1 - t))) sample[N_total - N_fade + i] = sample[N_total - N_fade + i] × gain For crossfade (overlap duration = overlap): For each sample i in overlap region: t = i / N_overlap gain_A = cos(π × t / 2) # Fading out gain_B = sin(π × t / 2) # Fading in sample_combined[i] = sample_A[i] × gain_A + sample_B[i] × gain_B

Batch Processing Logic

INPUT: start_times_list, end_times_list (comma-separated) STEP 1: Parse lists start_array = split(start_times_list, ",") end_array = split(end_times_list, ",") STEP 2: Validate equal length If length(start_array) ≠ length(end_array) → ERROR STEP 3: Process each interval FOR i = 1 to length(start_array): start = parse_number(start_array[i]) end = parse_number(end_array[i]) // Validate this interval IF start < 0 OR end > duration OR end ≤ start → ERROR (or skip) // Apply buffer if specified start = max(0, start - buffer_before) end = min(duration, end + buffer_after) // Apply duration constraints IF min_duration > 0 AND (end - start) < min_duration → skip IF max_duration > 0 AND (end - start) > max_duration → adjust // Extract segment extract_segment(start, end, fade_in, fade_out) // Name according to convention name = replace_placeholders(naming_convention, i, start, end) STEP 4: Handle overlaps if multiple intervals IF overlap_action = "skip" AND overlaps_exist → skip overlapping IF overlap_action = "merge" → combine overlapping intervals IF overlap_action = "crossfade" → apply crossfade in overlaps OUTPUT: Multiple Sound objects, one per (valid) interval