Learn R Programming

R package for sound synthesis and acoustic analysis.
Homepage with help, demos, etc: http://cogsci.se/soundgen.html

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.

Key functions

  • Sound synthesis from R console: soundgen()
  • Shiny app for sound synthesis (opens in a browser): soungen_app()
  • Acoustic analysis of a wav/mp3 file: analyze()
  • Shiny app for editing intonation contours (opens in a browser): pitch_app()
  • Measuring syllables, pauses, and bursts in a wav/mp3 file: segment()

For more information, please see the vignettes on sound synthesis and acoustic analysis and other tips at https://cogsci.se/soundgen.html

Example of sound synthesis

Use the soundgen() function to create a breathy moan:

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(-35, -25, -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)
)

Example of acoustic analysis

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')]
#>      pitch peakFreq harmHeight      HNR       ampl  loudness
#> 1       NA       NA         NA       NA 0.02203151  2.971372
#> 2 303.0399 300.1361   1063.385 12.61768 0.23630756 10.772501
#> 3 302.0111 300.1361   1052.351 21.29106 0.48501199 17.973918
#> 4 299.5857 300.1361   1049.926 21.05983 0.57804421 20.946816
#> 5 296.4350 300.1361   1036.771 19.61540 0.50244285 19.852580
colnames(a$detailed)
#>  [1] "duration"           "duration_noSilence" "time"               "amEnvDep"          
#>  [5] "amEnvDepVoiced"     "amEnvFreq"          "amEnvFreqVoiced"    "amMsFreq"          
#>  [9] "amMsFreqVoiced"     "amMsPurity"         "amMsPurityVoiced"   "ampl"              
#> [13] "ampl_noSilence"     "amplVoiced"         "CPP"                "dom"               
#> [17] "domVoiced"          "entropy"            "entropySh"          "entropyShVoiced"   
#> [21] "entropyVoiced"      "epoch"              "f1_freq"            "f1_width"          
#> [25] "f2_freq"            "f2_width"           "f3_freq"            "f3_width"          
#> [29] "flux"               "fmDep"              "fmFreq"             "fmPurity"          
#> [33] "harmEnergy"         "harmHeight"         "HNR"                "HNRVoiced"         
#> [37] "loudness"           "loudnessVoiced"     "novelty"            "noveltyVoiced"     
#> [41] "peakFreq"           "peakFreqVoiced"     "pitch"              "quartile25"        
#> [45] "quartile25Voiced"   "quartile50"         "quartile50Voiced"   "quartile75"        
#> [49] "quartile75Voiced"   "roughness"          "roughnessVoiced"    "specCentroid"      
#> [53] "specCentroidVoiced" "specSlope"          "specSlopeVoiced"    "subDep"            
#> [57] "subRatio"           "voiced"

Installation

To install the current release from CRAN: install.packages("soundgen")

NB: Make sure all dependencies have been installed correctly! On Macs, you may need to do the following:

  • First install brew according to the instructions here: https://brew.sh/
  • Then run the following from the terminal
    brew install libsndfile
    brew install fftw
  • Finally, install soundgen in R:
    install.packages("soundgen")

Copy Link

Version

Install

install.packages('soundgen')

Monthly Downloads

1,189

Version

2.8.0

License

GPL (>= 2)

Maintainer

Andrey Anikin

Last Published

December 14th, 2025

Functions in soundgen (2.8.0)

addVectors

Add overlapping vectors
annotation_app

Annotation app
analyzeFrame

Analyze fft frame
beat

Generate beat
analyze

Acoustic analysis
audSpectrogram

Auditory spectrogram
averageMatrices

Average matrices
checkInputType

Check audio input type
addSubh_per_epoch

Constant subharmonics
bandpass

Bandpass/stop filters
convertStringToFormants

Prepare a list of formants
crossFade

Join two waveforms by cross-fading
clumper

Clump a sequence into large segments
defaults

Shiny app defaults
costJumps

Cost of jumps
def_form

Defaults and ranges for formant_app()
convert_sec_to_hms

Print time
costPerPath

Cost per path
dPhase

Phase derivatives
detectNLP_training_nonv

Nonlinear phenomena: Naive Bayes classifier trained on human nonverbal vocalizations
detectNLP

Detect NLP
compareSounds

Compare two sounds
detectNLP_training_synth

Nonlinear phenomena: Naive Bayes classifier trained on synthetic sounds
divideIntoSyllables

Syllable structure of a bout
.addFormants

Add formants per sound
.analyze

Analyze per sound
defaults_analyze_pitchCand

Defaults for plotting with analyze()
defaults_analyze

Defaults and ranges for analyze()
.addAM

Add AM to a sound
.audSpectrogram

Auditory spectrogram per sound
.fade

Fade per sound
.bandpass

Bandpass filter per sound
.flatEnv

Flat envelope per sound
.flatSpectrum

Flat spectrum per sound
.detectNLP

Detect NLP per sound
.filterSoundByMS

Filter a single sound by MS
.getDuration

Get duration per sound
.getLoudness

Loudness per sound
.phasegram

Phasegram per sound
.osc

Oscillogram per sound
.resample

Resample per sound
.reverb

Add reverb to a sound
.getSurprisal

Get surprisal per sound
.modulationSpectrum

Modulation spectrum per sound
.getPitchZc

Zero-crossing rate per sound
.shiftFormants

Shift formants per sound
.getRMS

RMS amplitude per sound
fart

Fart
fade

Fade
.segment

Internal soundgen function
.spectrogram

Spectrogram per sound
.shiftPitch

Shift pitch per sound
.pitchDescriptives

Pitch descriptives per file
.prosody

Prosody per sound
drawContour

Draw contour
findInflections

Find inflections
.timeStretch

Time stretch per sound
.ssm

SSM per sound
filterSoundByMS

Filter sound by modulation spectrum
findJumps

Find frequency jumps
estimateVTL

Estimate vocal tract length
filterMS

Filter modulation spectrum
evaluatePars

Evaluate parameters for optimization
gaussianSmooth2D

Gaussian smoothing in 2D
formatPitchManual

Format pitchManual
drawFreqAxis

Draw frequency axis
filled.contour.mod

Modified filled.contour
findGrad

Find gradient
findPeaks

Find peaks
findVoicedSegments

Find voiced segments
findElbow

Find the elbow of a screeplot or similar
findZeroCrossing

Find zero crossing
getAM_env

Get Amplitude Modulation
generateEpoch

Generate an epoch
findSyllables

Find syllables
getBandwidth

Get bandwidth
generateGC

Generate glottal cycles
getCPP

Get Cepstral Peak Prominence
flatEnv

Flat envelope / compressor
flatSpectrum

Flat spectrum
getCheckerboardKernel

Checkerboard kernel
getFormantDispersion

Get formant dispersion
getHNR

Get HNR
getIntegerRandomWalk

Discrete random walk
getFeatureFlux

Get flux from features
getEnv

Get amplitude envelope
getDom

Get lowest dominant frequency band
getDiscreteContour

Discrete smooth contour from anchors
findBursts

Find bursts
forcePerPath

Force per path
getNovelty

SSM novelty
getPeakFreq

Get peak frequency
formant_app

Interactive formant tracker
generateNoise

Generate noise
getDuration

Get duration
getLoudness

Get loudness
getMelSpec

Mel-transformed spectrogram
getEntropy

Entropy
generateHarmonics

Generate harmonics
getPitchZc

Zero-crossing rate
getPitchCep

Cepstral pitch tracker
getPitchAutocor

Autocorrelation pitch tracker
getFormants

Get formants
getSpectralEnvelope

Spectral envelope
getSpectralFlux

Get spectral flux
getSmoothContour

Smooth contour from anchors
getSHR

Subharmonics-to-harmonics ratio
getGlottalCycles

Divide f0 contour into glottal cycles
getFrameBank

Frame bank
getSigmoid

Get sigmoid filter
getAM

Get amplitude modulation
getSmoothSpectrum

Get smooth spectrum
getRMS

RMS amplitude
getPitchSpec

BaNa pitch tracker
guessPhase_spsi

Guess phase SPSI
harmEnergy

Energy in harmonics
getPitchHps

Harmonic product spectrum
generatePath

Generate path
getSurprisal

Get surprisal
identifyAndPlay

Identify and play
getPrior

Get prior for pitch candidates
interpolMatrix

Interpolate matrix
harmHeight_dif

Height of harmonics: difference method
harmHeight

Height of harmonics
invertSpectrogram

Invert spectrogram
getSurprisal_matrix

Get surprisal per matrix
iso226

iso226
isNeighbour_mod

Is neighbor modified
logMatrix

Log-warp matrix
matchLengths

Resize vector to required length
matchColumns

Match number of columns
logWarpMS

Log-warp a modulation spectrum
getRough

Calculate roughness from modulation spectrum
getRolloff

Control rolloff of harmonics
matchPars

Match soundgen pars (experimental)
log01

log01
lockToFormants

Lock to formants
getSurprisal_vector

Get surprisal per vector
htmlPlots

HTML for clickable plots
modulationSpectrum

Modulation spectrum
morph

Morph sounds
guessPhase_GL

Guess phase GL
nonlinPred

Nonlinear prediction
getRandomWalk

Random walk
hz2mel

Convert Hz to mel
istft_mod

Modified istft
jet.col

Matlab colors
modulationSpectrumFragment

Modulation spectrum per fragment
msToSpec

Modulation spectrum to spectrogram
nonlinStats

Nonlinear statistics
na.trim

Trim leading and trailing NAs
osc

Oscillogram
logit

Logit
naiveBayes_train

Train a naive Bayes classifier
interpolate

Interpolate
naiveBayes_likelihood

Naive Bayes likelihood
logistic

Logistic
pDistr

Proportion of total
intplNA

Interpolate NAs
harmHeight_peaks

Height of harmonics: peaks method
normalizeFolder

Normalize folder
medianSmoother

Median smoothing
hillenbrand

Formants in American vowels
notesDict

Conversion table from Hz to musical notation
noiseRemoval

Noise removal
nonLinearPrediction_mod

Nonlinear prediction modified
morphDF

Morph dataframes
phasegram

Phasegram
killDC

Kill DC
morphFormants

Morph formants
pathfinding_slow

Path through pitch candidates: slow
pathfinding_fast

Path through pitch candidates: fast
optimizePars

Optimize parameters for acoustic analysis
objectToString

Object to string
naiveBayes

Naive Bayes
pitch_app

Interactive pitch tracker
naiveBayes_dynamicPrior

Naive Bayes dynamic prior
morphList

Morph lists
processAudio

Process audio
princarg

Principal argument
pitchSmoothPraat

Pitch smoothing as in Praat
playme

Play audio
parabPeakInterpol

Parabolic peak interpolation
plotMS

Plot modulation spectrum
plotSpec

Plot spectrogram
sampleModif

sampleModif
pathfinder

Pathfinder
pitchManual

Manual pitch estimation in 260 sounds
reverb

Reverb & echo
readAudio

Read audio
rnorm_truncated2

Random draw from a truncated normal distribution
rnorm_truncated

Random draw from a truncated normal distribution
phon2sone

Phon-sone conversion
prosody

Prosody
shiftPitch

Shift pitch
plotUnrasterized

Plot unrasterized spetrogram
sinc

Sinc
phasePropagate

Propagate phase
presets

Presets
permittedValues

Defaults and ranges for soundgen()
shiftFormants

Shift formants
reportTime

Report time
schwa

Schwa-related formant conversion
resample

Resample a vector
reformatFormants

Reformat formants
segmentManual

Manual counts of syllables in 260 sounds
reformatAnchors

Reformat anchors
silenceSegments

Silence sound segments
pitchContour

Manually corrected pitch contours in 260 sounds
transplantEnv

Transplant envelope
specToMS

Spectrogram to modulation spectrum
soundgen_app

Interactive sound synthesizer
pitchDescriptives

Pitch descriptives
segment

Segment a sound
upsampleGC

Upsample glottal cycles
splitIntoChunks

Split vector into chunks
reportCI

Report CI
summarizeAnalyze

Summarize the output of analyze()
pseudoLog

Pseudolog
selfsim

Compute self-similarity
pseudoLog_undo

Undo pseudolog
to_dB

Convert to dB
scaleNoiseAnchors

Scale noise anchors
splitContour

Split contour
switchColorTheme

Switch color theme
scaleSPL

Scale SPL
timeSeriesSummary

Time series summary
wigglePars

Wiggle parameters
validatePars

Validate parameters
wiggleGC

Wiggle glottal cycles
rbind_fill

rbind_fill
timeStretch

Time stretch
ssm

Self-similarity matrix
spreadSpec

Spread spectrum
warpMatrix

Warp matrix
spectrogram

Spectrogram
soundgen

Generate a sound
transplantFormants

Transplant formants
snake

Snake
updateAnalyze

Update analyze
specToMS_1D

Spectrogram to modulation spectrum 1D
zeroOne

Normalize 0 to 1
writeAudio

Write audio
wiggleAnchors

Randomly modify anchors
HzToERB

Convert Hz to ERB rate
HzToOther

Convert between Hz and other frequency scales
addPitchJumps

Add pitch jumps
Mode

Modified mode
HzToSemitones

Convert semitones to Hz and back
addAM

Add amplitude modulation
addFormants

Add formants
HzToNotes

Convert between Hz and notes
addSubh

Subharmonics
addPitchCands

Plot pitch candidates