Learn R Programming

soundgen readme

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.0352417  3.361811
#> 2 304.0203 300.1361   1368.385 13.57148 0.2611070 11.217886
#> 3 302.1499 300.1361         NA 20.99729 0.5078240 18.005310
#> 4 299.4880 300.1361   1049.828 19.95427 0.5918217 20.944904
#> 5 296.4051 300.1361   1629.551 19.15678 0.5082565 19.372810
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

2,954

Version

2.7.4

License

GPL (>= 2)

Maintainer

Andrey Anikin

Last Published

September 29th, 2025

Functions in soundgen (2.7.4)

checkInputType

Check audio input type
annotation_app

Annotation app
beat

Generate beat
bandpass

Bandpass/stop filters
analyze

Acoustic analysis
audSpectrogram

Auditory spectrogram
addVectors

Add overlapping vectors
addSubh_per_epoch

Constant subharmonics
averageMatrices

Average matrices
analyzeFrame

Analyze fft frame
crossFade

Join two waveforms by cross-fading
def_form

Defaults and ranges for formant_app()
compareSounds

Compare two sounds
defaults

Shiny app defaults
convert_sec_to_hms

Print time
convertStringToFormants

Prepare a list of formants
dPhase

Phase derivatives
costJumps

Cost of jumps
clumper

Clump a sequence into large segments
costPerPath

Cost per path
divideIntoSyllables

Syllable structure of a bout
detectNLP

Detect NLP
.addFormants

Add formants per sound
.audSpectrogram

Auditory spectrogram per sound
.analyze

Analyze per sound
detectNLP_training_synth

Nonlinear phenomena: Naive Bayes classifier trained on synthetic sounds
defaults_analyze

Defaults and ranges for analyze()
defaults_analyze_pitchCand

Defaults for plotting with analyze()
.getPitchZc

Zero-crossing rate per sound
.flatEnv

Flat envelope per sound
.getDuration

Get duration per sound
.getLoudness

Loudness per sound
.fade

Fade per sound
detectNLP_training_nonv

Nonlinear phenomena: Naive Bayes classifier trained on human nonverbal vocalizations
.filterSoundByMS

Filter a single sound by MS
.flatSpectrum

Flat spectrum per sound
.bandpass

Bandpass filter per sound
.addAM

Add AM to a sound
.getRMS

RMS amplitude per sound
.detectNLP

Detect NLP per sound
.modulationSpectrum

Modulation spectrum per sound
.prosody

Prosody per sound
.pitchDescriptives

Pitch descriptives per file
.reverb

Add reverb to a sound
.shiftFormants

Shift formants per sound
.resample

Resample per sound
.phasegram

Phasegram per sound
.getSurprisal

Get surprisal per sound
.osc

Oscillogram per sound
.segment

Internal soundgen function
fade

Fade
fart

Fart
estimateVTL

Estimate vocal tract length
.spectrogram

Spectrogram per sound
drawFreqAxis

Draw frequency axis
.shiftPitch

Shift pitch per sound
.ssm

SSM per sound
drawContour

Draw contour
evaluatePars

Evaluate parameters for optimization
.timeStretch

Time stretch per sound
findPeaks

Find peaks
findGrad

Find gradient
filterSoundByMS

Filter sound by modulation spectrum
filterMS

Filter modulation spectrum
findInflections

Find inflections
findJumps

Find frequency jumps
findElbow

Find the elbow of a screeplot or similar
filled.contour.mod

Modified filled.contour
findSyllables

Find syllables
findBursts

Find bursts
generateEpoch

Generate an epoch
findZeroCrossing

Find zero crossing
flatEnv

Flat envelope / compressor
flatSpectrum

Flat spectrum
formant_app

Interactive formant tracker
gaussianSmooth2D

Gaussian smoothing in 2D
formatPitchManual

Format pitchManual
forcePerPath

Force per path
generateGC

Generate glottal cycles
findVoicedSegments

Find voiced segments
getDiscreteContour

Discrete smooth contour from anchors
generateNoise

Generate noise
getAM

Get amplitude modulation
getCheckerboardKernel

Checkerboard kernel
generatePath

Generate path
getBandwidth

Get bandwidth
generateHarmonics

Generate harmonics
getAM_env

Get Amplitude Modulation
getDom

Get lowest dominant frequency band
getCPP

Get Cepstral Peak Prominence
getFrameBank

Frame bank
getDuration

Get duration
getFormantDispersion

Get formant dispersion
getEnv

Get amplitude envelope
getHNR

Get HNR
getIntegerRandomWalk

Discrete random walk
getFeatureFlux

Get flux from features
getEntropy

Entropy
getGlottalCycles

Divide f0 contour into glottal cycles
getFormants

Get formants
getPeakFreq

Get peak frequency
getNovelty

SSM novelty
getPitchAutocor

Autocorrelation pitch tracker
getPrior

Get prior for pitch candidates
getPitchSpec

BaNa pitch tracker
getLoudness

Get loudness
getPitchZc

Zero-crossing rate
getMelSpec

Mel-transformed spectrogram
getPitchCep

Cepstral pitch tracker
getPitchHps

Harmonic product spectrum
getSmoothContour

Smooth contour from anchors
getRMS

RMS amplitude
getSpectralFlux

Get spectral flux
getSpectralEnvelope

Spectral envelope
getRolloff

Control rolloff of harmonics
getRandomWalk

Random walk
getSmoothSpectrum

Get smooth spectrum
getSigmoid

Get sigmoid filter
getSHR

Subharmonics-to-harmonics ratio
getRough

Calculate roughness from modulation spectrum
getSurprisal_matrix

Get surprisal per matrix
harmEnergy

Energy in harmonics
guessPhase_GL

Guess phase GL
getSurprisal

Get surprisal
hillenbrand

Formants in American vowels
getSurprisal_vector

Get surprisal per vector
harmHeight_peaks

Height of harmonics: peaks method
harmHeight_dif

Height of harmonics: difference method
harmHeight

Height of harmonics
guessPhase_spsi

Guess phase SPSI
invertSpectrogram

Invert spectrogram
istft_mod

Modified istft
isNeighbour_mod

Is neighbor modified
identifyAndPlay

Identify and play
interpolate

Interpolate
iso226

iso226
intplNA

Interpolate NAs
logit

Logit
logistic

Logistic
logWarpMS

Log-warp a modulation spectrum
interpolMatrix

Interpolate matrix
htmlPlots

HTML for clickable plots
hz2mel

Convert Hz to mel
matchLengths

Resize vector to required length
jet.col

Matlab colors
logMatrix

Log-warp matrix
matchColumns

Match number of columns
log01

log01
killDC

Kill DC
lockToFormants

Lock to formants
na.trim

Trim leading and trailing NAs
msToSpec

Modulation spectrum to spectrogram
morph

Morph sounds
modulationSpectrum

Modulation spectrum
matchPars

Match soundgen pars (experimental)
medianSmoother

Median smoothing
morphDF

Morph dataframes
modulationSpectrumFragment

Modulation spectrum per fragment
morphList

Morph lists
morphFormants

Morph formants
nonlinPred

Nonlinear prediction
noiseRemoval

Noise removal
naiveBayes_dynamicPrior

Naive Bayes dynamic prior
naiveBayes

Naive Bayes
normalizeFolder

Normalize folder
naiveBayes_likelihood

Naive Bayes likelihood
naiveBayes_train

Train a naive Bayes classifier
nonLinearPrediction_mod

Nonlinear prediction modified
nonlinStats

Nonlinear statistics
notesDict

Conversion table from Hz to musical notation
osc

Oscillogram
pathfinding_slow

Path through pitch candidates: slow
permittedValues

Defaults and ranges for soundgen()
pDistr

Proportion of total
pathfinder

Pathfinder
objectToString

Object to string
optimizePars

Optimize parameters for acoustic analysis
pathfinding_fast

Path through pitch candidates: fast
parabPeakInterpol

Parabolic peak interpolation
phasePropagate

Propagate phase
plotSpec

Plot spectrogram
pitchManual

Manual pitch estimation in 260 sounds
pitchDescriptives

Pitch descriptives
phasegram

Phasegram
pitch_app

Interactive pitch tracker
pitchContour

Manually corrected pitch contours in 260 sounds
playme

Play audio
plotMS

Plot modulation spectrum
pitchSmoothPraat

Pitch smoothing as in Praat
plotUnrasterized

Plot unrasterized spetrogram
princarg

Principal argument
prosody

Prosody
phon2sone

Convert phon to sone
processAudio

Process audio
reverb

Reverb & echo
sampleModif

sampleModif
presets

Presets
scaleSPL

Scale SPL
rbind_fill

rbind_fill
pseudoLog_undo

Undo pseudolog
rnorm_truncated2

Random draw from a truncated normal distribution
resample

Resample a vector
reportTime

Report time
rnorm_truncated

Random draw from a truncated normal distribution
readAudio

Read audio
pseudoLog

Pseudolog
reformatAnchors

Reformat anchors
scaleNoiseAnchors

Scale noise anchors
reportCI

Report CI
reformatFormants

Reformat formants
schwa

Schwa-related formant conversion
segment

Segment a sound
shiftFormants

Shift formants
shiftPitch

Shift pitch
selfsim

Compute self-similarity
snake

Snake
silenceSegments

Silence sound segments
segmentManual

Manual counts of syllables in 260 sounds
soundgen

Generate a sound
sinc

Sinc
splitContour

Split contour
specToMS_1D

Spectrogram to modulation spectrum 1D
spectrogram

Spectrogram
specToMS

Spectrogram to modulation spectrum
soundgen_app

Interactive sound synthesizer
summarizeAnalyze

Summarize the output of analyze()
switchColorTheme

Switch color theme
ssm

Self-similarity matrix
spreadSpec

Spread spectrum
splitIntoChunks

Split vector into chunks
timeStretch

Time stretch
timeSeriesSummary

Time series summary
wiggleAnchors

Randomly modify anchors
warpMatrix

Warp matrix
transplantEnv

Transplant envelope
transplantFormants

Transplant formants
updateAnalyze

Update analyze
validatePars

Validate parameters
to_dB

Convert to dB
upsampleGC

Upsample glottal cycles
wigglePars

Wiggle parameters
zeroOne

Normalize 0 to 1
writeAudio

Write audio
wiggleGC

Wiggle glottal cycles
addPitchCands

Plot pitch candidates
Mode

Modified mode
addAM

Add amplitude modulation
HzToSemitones

Convert semitones to Hz and back
addFormants

Add formants
HzToNotes

Convert between Hz and notes
addSubh

Subharmonics
HzToOther

Convert between Hz and other frequency scales
HzToERB

Convert Hz to ERB rate
addPitchJumps

Add pitch jumps