segment_ann: Extract annotated syllables

View source: R/segment_utilities.R

segment_annR Documentation

Extract annotated syllables

Description

Takes a table of syllable annotations, formatted as the syllables dataframe returned by segment, extracts the corresponding audio segments, and saves each segment as a separate .wav file in a subdirectory named "segment".

Usage

segment_ann(
  syllables,
  x,
  samplingRate = NULL,
  scale = NULL,
  addSilence = 50,
  path = NULL
)

Arguments

syllables

data frame with at least columns start and end (ms), e.g. the syllables data frame returned by segment

x

path to a .wav or .mp3 file, a Wave object, or a numeric vector

samplingRate

sampling rate of x; only needed if x is a numeric vector

scale

maximum possible amplitude of x; only needed if x is a numeric vector. If NULL, the scale is guessed from the maximum observed amplitude

addSilence

silence added before and after each extracted segment, ms

path

optional full path to the directory in which to save the extracted segments. If NULL, a subdirectory named "segment" is created either in the folder containing the audio file (if x is a file) or in the working directory (if x is a Wave object or numeric vector)

Details

If x is a path to an audio file, the default output directory is segment inside the folder containing that file. If x is a Wave object or a numeric vector, the default output directory is segment inside the current working directory. Use path to override the output location.

Value

Does not return anything, just saves the files.

See Also

segment

Examples

sound = soundgen(nSyl = 3, sylLen = 100, pauseLen = 70,
                 pitch = 250, temperature = 0.001)
s = segment(sound, samplingRate = 16000, plot = FALSE)
s$syllables
# the annotation table should look like this, with start/end times in ms!

## Not run: 
# extract and save all syllables
segment_ann(s$syllables, sound, samplingRate = 16000)

# save to a custom folder
segment_ann(s$syllables, sound, samplingRate = 16000,
            path = '~/Downloads/temp_segment')

## End(Not run)

soundgen documentation built on Sept. 20, 2026, 5:07 p.m.