extract_mfcc: Extract MFCCs for vowel segments

View source: R/mfcc_helpers.R

extract_mfccR Documentation

Extract MFCCs for vowel segments

Description

Adds MFCC feature columns (e.g., mfcc1..mfcc13) to a data frame that contains audio file paths and (optionally) segment boundaries.

Usage

extract_mfcc(
  data,
  file_col,
  start_col = NULL,
  end_col = NULL,
  fs = NULL,
  numcep = 13,
  prefix = "mfcc",
  strict = FALSE,
  warn = TRUE,
  ...
)

Arguments

data

Data frame containing audio paths and segment boundaries.

file_col

String; column name containing WAV file paths.

start_col

Optional string; column name containing segment start time (in seconds). If NULL, the full file is used.

end_col

Optional string; column name containing segment end time (in seconds). If NULL, the full file is used.

fs

Optional numeric; override sampling rate (Hz). If NULL, uses the file's sampling rate.

numcep

Integer; number of MFCC coefficients to return.

prefix

String; prefix for output columns (default "mfcc").

strict

Logical; if TRUE, stop on the first row that cannot be processed. If FALSE (default), leave that row's MFCC values as NA.

warn

Logical; if TRUE (default), warn when one or more rows cannot be processed and strict = FALSE.

...

Additional arguments passed to tuneR::melfcc().

Details

This function uses tuneR to read WAV files and compute MFCCs. The package is optional; if it is not installed, an informative error is raised.

Value

The input data frame with added MFCC columns.

Examples

if (requireNamespace("tuneR", quietly = TRUE)) {
  wav_path <- tempfile(fileext = ".wav")
  wave <- tuneR::sine(
    freq = 440, duration = 0.25, samp.rate = 16000, xunit = "time"
  )
  tuneR::writeWave(wave, wav_path)

  segments <- data.frame(wav_path = wav_path)
  mfcc <- extract_mfcc(segments, file_col = "wav_path", numcep = 3)
  unlink(wav_path)
  mfcc[, c("mfcc1", "mfcc2", "mfcc3")]
}

phontrast documentation built on Oct. 7, 2026, 5:06 p.m.