rspectVid

Script for generating a dynamic, multi-paged video spectrogram from an audio file in R

View the Project on GitHub drwilkins/rspectVid

rspectVid

Script for generating a dynamic spectrogram from an audio file Now supports multipaged videos with sliding highlight (akin to Audition)

Workflow:

  1. Tweak your spectrogram settings using the testSpec() function, storing results in variable
  2. Feed variable into rspectVid to generate dynamic spectrogram -It does this by exporting a PNG of the testSpec() ggplot function; -Import PNG as a new ggplot raster layer -Overlay a series of translucent highlight boxes that disolve away using gganimate

To source the rspectVid.R script & generate a dynamic spec in a new R instance:

Example usage:

require(devtools)
source_url("https://raw.githubusercontent.com/drwilkins/rspectVid/master/rspectVid.R")
#takes .wav or .mp3
params<-testSpec("data/Femalebarnswallow1.wav", onlyPlotSpec=F) 
ggsave("web/femStaticSongSpec.png",params$spec[[1]])
rspectVid(params,vidName="femDynamicSongSpec",destFolder="web/") 
#exports an .mp4 to the same file directory by default

Static spectrogram of a female barn swallow song

Static Spectrogram of a female barn swallow song

Dynamic spectrogram of a female barn swallow song

Now brighten the spec using the ampTrans parameter

p2<-testSpec("data/Femalebarnswallow1.wav",min_dB=-35, onlyPlotSpec=F,bgFlood=T,ampTrans=3) 
rspectVid(p2,destFolder="web/") 

Now also supports .mp3 files (web or local) and multi-page dynamic spectrograms (i.e. cropping and segmenting spectrograms from larger recording files)


p<-testSpec("http://www.oceanmammalinst.org/songs/hmpback3.wav",yLim=c(0,.7),crop=12,xLim=3,ampTrans=3) 
ggsave("web/humpback.png", height=2, width=6)
rspectVid(p,destFolder="web/",delTemps=F)
#Voila 🐋

Static whale song spectrogram

Humpback whale song spectrogram

Dynamic multipage whale song spectrogram

<iframe src=”https://player.vimeo.com/video/432723336” style=”border:0px” frameborder=”0” height=303 width=910 allow=”autoplay; fullscreen” allowfullscreen></iframe>

Example using Xeno-Canto to generate a multi-page dynamic spectrogram of a common nighthawk call (w/ different color scheme)

song="https://www.xeno-canto.org/sounds/uploaded/SPMWIWZKKC/XC490771-190804_1428_CONI.mp3"
n=testSpec(song,crop=20,xLim=4,colPal = c("white","black"))
rspectVid(n,vidName="nightHawk" ,highlightCol = "#d1b0ff",cursorCol = "#7817ff",destFolder="web/")
### Nighthawk multipage dynamic spec <iframe src="https://player.vimeo.com/video/432724657" style="border:0px; width: 100%;" height=303 width=910 margin="0" padding="0" frameborder="0" allow="autoplay; fullscreen" allowfullscreen></iframe>