stopifnot(require(knitr)) options(width = 90) knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", dev = "png", dpi = 150, fig.asp = 0.7, fig.width = 8, out.width = "80%", fig.align = "center" ) library(soundgen)
R package for sound synthesis and acoustic analysis.
Homepage with help, demos, etc: http://cogsci.se/soundgen.html
Source code on github: https://github.com/tatters/soundgen
Performs parametric synthesis of sounds with harmonic and noise components such as animal vocalizations or human voice. Also includes tools for spectral analysis, pitch tracking, audio segmentation, self-similarity matrices, morphing, etc.
soundgen()
soungen_app()
analyze()
pitch_app()
segment()
For more information, please see the vignettes on sound synthesis and acoustic analysis and other tips at https://cogsci.se/soundgen.html
Use the soundgen()
function to create a breathy moan:
file.remove('man/figures/s.mp3')
s = soundgen( sylLen = 230, # duration of voiced part, ms pitch = c(305, 280), # pitch, Hz (goes down from 305 to 380 Hz) ampl = c(0, -20), # amplitude, dB (gradual fade-out by 20 dB) rolloff = -30, # strong f0, weak harmonics temperature = 0.05, # some stochasticity in generation formants = c(260, 960, 1500, 2200, # F1-F8 formant frequencies, Hz 2600, 3600, 4200, 4500), noise = data.frame( time = c(-50, 120, 700), # time of noise anchors value = c(-15, -5, -50) # noise amplitude, dB ), rolloffNoise = 0, # flat noise spectrum before adding formants addSilence = 0, samplingRate = 44100, pitchSamplingRate = 44100, play = TRUE, plot = TRUE, osc = TRUE, ylim = c(0, 6) )
seewave::savewav(s, f = 44100, filename = 'man/figures/s.wav') system('ffmpeg -y -i man/figures/s.wav man/figures/s.mp3') file.remove('man/figures/s.wav')
Use the analyze()
function to detect pitch and obtain other spectral descriptives of the sound we have just synthesized:
a = analyze(s, 44100, plot = TRUE, ylim = c(0, 6)) a$detailed[1:5, c('pitch', 'peakFreq', 'harmHeight', 'HNR', 'ampl', 'loudness')] colnames(a$detailed)
To install the current release from CRAN: install.packages("soundgen")
NB: Make sure all dependencies have been installed correctly! For problems with seewave, see https://rug.mnhn.fr/seewave/
On Macs, you may need to do the following:
brew install libsndfile
brew install fftw
install.packages("soundgen")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.