sox_spectro | R Documentation |
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.
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
)
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. |
Most arguments are passed through to the seewave::sox()
command.
width and height correspond to the -x
and -y
options for the
spectrogram
effect.
start
and end
are used by the trim
effect
rate
is passed on to the rate
effect
Based on code from Sam Hache.
Does not return anything, but creates a spectrogram image in
dir_out
.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.