Wave objects. Extract short or long wave files, play audio while viewing spectrogram, and annotate sounds in the spectrogram. Load annotations from csv files for viewing.viewSpec(clip, interactive=FALSE, start.time = 0,
units = "seconds", page.length = 30,
annotate = FALSE, anno, channel = "left",
output.dir = getwd(), frq.lim = c(0, 12), spec.col = gray.3(),
page.ovlp = 0.25, player = "play", wl = 512, ovlp = 0,
wn = "hanning", consistent = TRUE,
mp3.meta = list(kbps=128, samp.rate=44100, stereo=TRUE),
main=NULL, ...)FALSE displays the first 30 seconds (or more, if page.length is increased) of a spectrogram. TRUE enables the options to page through spectrograms, zoom in time and frequency, play, extract segments, and ac("seconds", "minutes", "hours") Defaults to "seconds".annotate=TRUE.c("left", "right", "both"). Stereo recordings may be viewed as single channel or multi-channel spectrograms. See Details.c(128, 256, 512, 1024, 2048)"hanning"; "hamming" is also implemented.kbps is the compression rate, samp.rate is the sample rate, and stereo is logical where TRUE represents both stereo and JntStereo.NULL the file name will be used if possible.spectrointeractive=TRUE, during the function session the console will display a command menu that prints commands to scroll or nudge to the next/previous page, zoom in/out in the time axis (by halving or doubling the page.length), play the page, save the page as a wave file, change spectrogram parameters (e.g. frq.lim, start.time, wl, ovlp, etc), or quit. An option not presented on-screen is "i" to identify the RMS amplitude in a selected portion of the spectrogram.
viewSpec relies on the WaveIO functions in tuneR, with some modifications. Seeking in wave files and wave objects is accurate to the nearest sample, but the decoding required for mp3 files is "bare bones". Users can install the software mp3splt which will allow seeking in mp3 files very similar (albeit slightly less accurate) to that that exists for wave files. When using mp3splt a short mp3 file the duration of each page is extracted from the clip file or object and saved to the working directory for each new page.
When annotation is set to TRUE the default is to start a new annotation file, unless a csv file containing annotations is specified with the argument anno. Annotation adds the option to annotate to the console command menu, and annotations can be made after typing "a" into the console and pressing enter. Annotation is accomplished by selecting first the upper-left corner of a bounding box around an event in the spectrogram followed by the lower-right corner; after the selection is complete the console will prompt to name the annotation. At a minimum the first annotation must be named, but subsequent annotations will recycle the previous name if a new one is not provided. When in annotation mode the console menu is not shown; instructions for annotation are displayed instead. To exit annotation mode right-click an appropriate number of times, and the console command menu will return. One or more annotations can be deleted by typing "d" in the console after the command menu is displayed, then bounding all annotations to delete in the same manner as if creating a new annotation. Annotations are saved when the command to exit the function is initiated ("q"). Occasionally unrecognized commands may cause the function to exit before annotations can be saved; to guard against losing annotations in such an event, annotations are auto-saved to a file called "TMPannotations.csv" in the working directory, from where they can be retrieved until written over during the next session. Annotation is only possible in one channel per function invocation. The channel will revert to "left" if annotate=TRUE and channel="both".
Spectrogram colors are adjustable, and users may opt to create their own gradients for display. A few are provided with monitoR including gray.1, gray.2, gray.3, rainbow.1, and topo.1, all of which are based on existing R colors. The gradient is mapped to the values in the spectrogram each time the page is loaded. In gray.2, for example, this means that every page will display the highest dB value as black and the lowest value as white. The highest dB value likely changes from page to page, which can result in successive pages being displayed with wildly different color values. Setting consistent=TRUE (the default) offers a way to minimize this effect, as it artificially weights a single cell in the lower-left corner with a value of 0 dB, which is usually mapped to a black. Under normal circumstances this artificially black cell will not be noticed, but at high magnification it may stand out as erroneous, in which case setting consistent=FALSE may be warranted.
Spectrograms of existing Wave objects are titled with the first argument of the call, which is assumed to be clip.
The default audio player, "play", is the shell command for SoX, the multi-OS media player. Windows will detect the file type and use the default media player with "start". Use the Windows syntax: START [/D path], which will equate to player="start /D " . On Ubuntu try Rhythmbox ("rhythmbox"), and on Mac OS try afplay ("afplay").dbUploadAnnodata(survey)
viewSpec(survey)
# Start a new annotation file
viewSpec(survey, annotate=TRUE)
# View previous annotations
data(survey_anno)
write.csv(survey_anno, "survey_anno.csv", row.names=FALSE)
viewSpec(survey, interactive=TRUE, annotate=TRUE, anno="survey_anno.csv", start.time=5)
# Disable consistent spectrograms
viewSpec(survey, interactive=TRUE, annotate=TRUE, page.length=10, consistent=FALSE)Run the code above in your browser using DataLab