sox_spectro {ARUtools}R Documentation

Create spectrogram image from wave file

Description

Using the external program SoX (the Swiss Army knife of sound processing programs), create a spectrogram image file. Note that you must have SoX installed to use this function. Spectrograms will be silently overwritten.

Usage

sox_spectro(
  path,
  dir_out = "Spectrograms",
  prepend = "spectro_",
  width = NULL,
  height = NULL,
  start = NULL,
  end = NULL,
  rate = "20k",
  dry_run = FALSE,
  quiet = FALSE,
  sox_file_path = NULL,
  skip_check = FALSE
)

Arguments

path

Character. Path to wave file.

dir_out

Character. Output directory.

prepend

Character. Text to add to the start of the output file. Defaults to "spectro_".

width

Numeric. Width of the spectrogram image in pixels.

height

Numeric. Height of the spectrogram image in pixels.

start

Numeric/Character. Start the spectrogram at this time (seconds or HH:MM:SS format).

end

Numeric/Character. End time the spectrogram at this time (seconds or HH:MM:SS format).

rate

Numeric. Audio sampling rate to display (used by the rate effect in sox). This effectively limits the upper frequency of the spectrogram to rate/2. The default ("20k"), limits the spectrogram to 10kHz. Use rate = NULL for no limiting.

dry_run

Logical. If TRUE show the sox command, but do not run (for debugging and understanding precise details).

quiet

Logical. Whether to suppress progress messages and other non-essential updates.

sox_file_path

Path to sox file if not installed at the system level, otherwise NULL.

skip_check

Logical. Should the function skip check to ensure SoX is installed. This may allow speed ups if running across large numbers of files.

Details

Most arguments are passed through to the seewave::sox() command.

Based on code from Sam Hache.

Value

Does not return anything, but creates a spectrogram image in dir_out.

Examples

# Prep sample file
w <- tuneR::sine(440, duration = 300000)
td <- tempdir()
temp_wave <- glue::glue("{td}/test_wave.wav")
tuneR::writeWave(w, temp_wave)

# Create spectrograms

try({sox_spectro(temp_wave)
sox_spectro(temp_wave, rate = NULL)
sox_spectro(temp_wave, start = 2, end = 3)
sox_spectro(temp_wave, start = "0:01", end = "0:04")
sox_spectro(temp_wave, prepend = "")
})

# Clean up
unlink(temp_wave)
unlink("Spectrograms", recursive = TRUE)

[Package ARUtools version 0.6.2 Index]