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 |
dry_run |
Logical. If |
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.
width and height correspond to the
-x
and-y
options for thespectrogram
effect.-
start
andend
are used by thetrim
effect -
rate
is passed on to therate
effect
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)