sound = c(soundgen(),
soundgen(nSyl = 4, sylLen = 50, pauseLen = 70,
formants = NA, pitch = c(500, 330)))
# playme(sound)
# detailed, local features (captures each syllable)
s1 = ssm(sound, samplingRate = 16000, kernelLen = 100)
# more global features (captures the transition b/w the two sounds)
s2 = ssm(sound, samplingRate = 16000, kernelLen = 400)
s2$summary
s2$detailed$novelty # novelty contour
if (FALSE) {
ssm(sound, samplingRate = 16000,
specFun = 'mfcc', simil = 'cor', normalize = TRUE,
ssmWin = 10, # speed up the processing
kernelLen = 300, # global features
specPars = list(colorTheme = 'seewave'),
ssmPars = list(col = rainbow(100)),
noveltyPars = list(type = 'l', lty = 3, lwd = 2))
# Custom input: produce a nice spectrogram first, then feed it into ssm()
sp = spectrogram(sound, 16000, windowLength = c(5, 40), contrast = .3,
output = 'processed') # return the modified spectrogram
ssm(sound, 16000, kernelLen = 400, specFun = sp)
# Custom input: use acoustic features returned by analyze()
an = analyze(sound, 16000, windowLength = 20, novelty = NULL)
feature_mat = t(an$detailed[, 4:ncol(an$detailed)]) # or select pitch, HNR, ...
feature_mat = t(apply(feature_mat, 1, scale)) # z-transform all variables
feature_mat[is.na(feature_mat)] = 0 # get rid of NAs
colnames(feature_mat) = an$detailed$time # time stamps in ms
rownames(feature_mat) = 1:nrow(feature_mat)
image(t(feature_mat)) # not a spectrogram, just a feature matrix
ssm(sound, 16000, kernelLen = 500, specFun = feature_mat, logSpec = FALSE,
specPars = list(ylab = 'Feature'))
}
Run the code above in your browser using DataLab