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()

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(-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)
)

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.02993491       NA
#> 2 291.4030 300.1361   582.8060  5.743706 0.19258955 11.19230
#> 3 293.9992 300.1361   881.9977 13.480664 0.41832141 18.21197
#> 4 293.8760 300.1361   881.9977 13.757051 0.53108777 22.46051
#> 5 292.1780 300.1361  1753.0680 12.266983 0.49117243 21.69834
colnames(a$detailed)
#>  [1] "duration"           "duration_noSilence" "time"               "amDep"             
#>  [5] "amDepVoiced"        "amFreq"             "amFreqVoiced"       "ampl"              
#>  [9] "amplVoiced"         "dom"                "domVoiced"          "entropy"           
#> [13] "entropyVoiced"      "epoch"              "f1_freq"            "f1_width"          
#> [17] "f2_freq"            "f2_width"           "f3_freq"            "f3_width"          
#> [21] "flux"               "harmEnergy"         "harmHeight"         "HNR"               
#> [25] "HNRVoiced"          "loudness"           "loudnessVoiced"     "novelty"           
#> [29] "noveltyVoiced"      "peakFreq"           "peakFreqVoiced"     "pitch"             
#> [33] "quartile25"         "quartile25Voiced"   "quartile50"         "quartile50Voiced"  
#> [37] "quartile75"         "quartile75Voiced"   "roughness"          "roughnessVoiced"   
#> [41] "specCentroid"       "specCentroidVoiced" "specSlope"          "specSlopeVoiced"   
#> [45] "subDep"             "subRatio"           "voiced"

Installation

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:

  • 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

623

Version

2.7.3

License

GPL (>= 2)

Maintainer

Andrey Anikin

Last Published

July 17th, 2025

Functions in soundgen (2.7.3)

addPitchJumps

Add pitch jumps
HzToERB

Convert Hz to ERB rate
addAM

Add amplitude modulation
Mode

Modified mode
ERBToHz

Convert Hz to ERB rate
HzToSemitones

Convert Hz to semitones
addFormants

Add formants
HzToNotes

Convert Hz to notes
addSubh

Subharmonics
addPitchCands

Plot pitch candidates
bandpass

Bandpass/stop filters
averageMatrices

Average matrices
beat

Generate beat
analyze

Acoustic analysis
addVectors

Add overlapping vectors
analyzeFrame

Analyze fft frame
checkInputType

Check audio input type
addSubh_per_epoch

Constant subharmonics
annotation_app

Annotation app
crossFade

Join two waveforms by cross-fading
clumper

Clump a sequence into large segments
costJumps

Cost of jumps
audSpectrogram

Auditory spectrogram
def_form

Defaults and ranges for formant_app()
defaults

Shiny app defaults
compareSounds

Compare two sounds
detectNLP_training_synth

Nonlinear phenomena: Naive Bayes classifier trained on synthetic sounds
dPhase

Phase derivatives
convertStringToFormants

Prepare a list of formants
convert_sec_to_hms

Print time
detectNLP

Detect NLP
defaults_analyze_pitchCand

Defaults for plotting with analyze()
defaults_analyze

Defaults and ranges for analyze()
.audSpectrogram

Auditory spectrogram per sound
.analyze

Analyze per sound
costPerPath

Cost per path
detectNLP_training_nonv

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

Syllable structure of a bout
.getPitchZc

Zero-crossing rate per sound
.bandpass

Bandpass filter per sound
.getDuration

Get duration per sound
.detectNLP

Detect NLP per sound
.addFormants

Add formants per sound
.getLoudness

Loudness per sound
.getRMS

RMS amplitude per sound
.addAM

Add AM to a sound
.fade

Fade per sound
.modulationSpectrum

Modulation spectrum per sound
.reverb

Add reverb to a sound
.getSurprisal

Get surprisal per sound
.resample

Resample per sound
.segment

Internal soundgen function
.filterSoundByMS

Filter a single sound by MS
fade

Fade
fart

Fart
.flatEnv

Flat envelope per sound
.flatSpectrum

Flat spectrum per sound
.shiftFormants

Shift formants per sound
.pitchDescriptives

Pitch descriptives per file
findInflections

Find inflections
findJumps

Find frequency jumps
filterSoundByMS

Filter sound by modulation spectrum
.prosody

Prosody per sound
.timeStretch

Time stretch per sound
findGrad

Find gradient
drawFreqAxis

Draw frequency axis
drawContour

Draw contour
.shiftPitch

Shift pitch per sound
filterMS

Filter modulation spectrum
flatEnv

Flat envelope / compressor
formatPitchManual

Format pitchManual
.osc

Oscillogram per sound
.ssm

SSM per sound
filled.contour.mod

Modified filled.contour
findElbow

Find the elbow of a screeplot or similar
.phasegram

Phasegram per sound
.spectrogram

Spectrogram per sound
estimateVTL

Estimate vocal tract length
gaussianSmooth2D

Gaussian smoothing in 2D
flatSpectrum

Flat spectrum
formant_app

Interactive formant tracker
findSyllables

Find syllables
getBandwidth

Get bandwidth
forcePerPath

Force per path
findBursts

Find bursts
evaluatePars

Evaluate parameters for optimization
findPeaks

Find peaks
getDiscreteContour

Discrete smooth contour from anchors
getAM_env

Get Amplitude Modulation
generateNoise

Generate noise
getEnv

Get amplitude envelope
getDom

Get lowest dominant frequency band
getFeatureFlux

Get flux from features
findVoicedSegments

Find voiced segments
getAM

Get amplitude modulation
generatePath

Generate path
generateGC

Generate glottal cycles
generateEpoch

Generate an epoch
getHNR

Get HNR
getFormants

Get formants
getIntegerRandomWalk

Discrete random walk
getDuration

Get duration
getFormantDispersion

Get formant dispersion
findZeroCrossing

Find zero crossing
getFrameBank

Frame bank
generateHarmonics

Generate harmonics
getCheckerboardKernel

Checkerboard kernel
getCPP

Get Cepstral Peak Prominence
getEntropy

Entropy
getPitchAutocor

Autocorrelation pitch tracker
getLoudness

Get loudness
getPitchZc

Zero-crossing rate
getPrior

Get prior for pitch candidates
getPitchCep

Cepstral pitch tracker
getPitchHps

Harmonic product spectrum
getNovelty

SSM novelty
getGlottalCycles

Divide f0 contour into glottal cycles
getMelSpec

Mel-transformed spectrogram
getPeakFreq

Get peak frequency
getPitchSpec

BaNa pitch tracker
getSpectralEnvelope

Spectral envelope
getSHR

Subharmonics-to-harmonics ratio
getRMS

RMS amplitude
getRolloff

Control rolloff of harmonics
getSpectralFlux

Get spectral flux
getRandomWalk

Random walk
getSmoothContour

Smooth contour from anchors
getSigmoid

Get sigmoid filter
getSmoothSpectrum

Get smooth spectrum
getRough

Calculate roughness from modulation spectrum
guessPhase_GL

Guess phase GL
getSurprisal

Get surprisal
getSurprisal_vector

Get surprisal per vector
harmHeight_dif

Height of harmonics: difference method
harmHeight_peaks

Height of harmonics: peaks method
harmEnergy

Energy in harmonics
hillenbrand

Formants in American vowels
guessPhase_spsi

Guess phase SPSI
harmHeight

Height of harmonics
getSurprisal_matrix

Get surprisal per matrix
invertSpectrogram

Invert spectrogram
isNeighbour_mod

Is neighbor modified
htmlPlots

HTML for clickable plots
istft_mod

Modified istft
identifyAndPlay

Identify and play
jet.col

Matlab colors
hz2mel

Hz to mel
interpolMatrix

Interpolate matrix
interpolate

Interpolate
intplNA

Interpolate NAs
lockToFormants

Lock to formants
logistic

Logistic
log01

log01
logit

Logit
listDepth

List depth
killDC

Kill DC
matchColumns

Match number of columns
iso226

iso226
logWarpMS

Log-warp a modulation spectrum
modulationSpectrumFragment

Modulation spectrum per fragment
logMatrix

Log-warp matrix
matchLengths

Resize vector to required length
matchPars

Match soundgen pars (experimental)
morphList

Morph lists
morphFormants

Morph formants
morphDF

Morph dataframes
msToSpec

Modulation spectrum to spectrogram
modulationSpectrum

Modulation spectrum
morph

Morph sounds
medianSmoother

Median smoothing
naiveBayes

Naive Bayes
naiveBayes_train

Train a naive Bayes classifier
normalizeFolder

Normalize folder
naiveBayes_likelihood

Naive Bayes likelihood
na.trim

Trim leading and trailing NAs
nonlinStats

Nonlinear statistics
naiveBayes_dynamicPrior

Naive Bayes dynamic prior
notesToHz

Convert notes to Hz
noiseRemoval

Noise removal
nonLinearPrediction_mod

Nonlinear prediction modified
notesDict

Conversion table from Hz to musical notation
pDistr

Proportion of total
objectToString

Object to string
osc

Oscillogram
nonlinPred

Nonlinear prediction
parabPeakInterpol

Parabolic peak interpolation
optimizePars

Optimize parameters for acoustic analysis
pathfinding_fast

Path through pitch candidates: fast
playme

Play audio
permittedValues

Defaults and ranges for soundgen()
pitch_app

Interactive pitch tracker
pitchDescriptives

Pitch descriptives
pathfinder

Pathfinder
phasePropagate

Propagate phase
pitchSmoothPraat

Pitch smoothing as in Praat
phasegram

Phasegram
phon2sone

Convert phon to sone
pitchContour

Manually corrected pitch contours in 260 sounds
pitchManual

Manual pitch estimation in 260 sounds
pathfinding_slow

Path through pitch candidates: slow
plotMS

Plot modulation spectrum
princarg

Principal argument
pseudoLog_undo

Undo pseudolog
prosody

Prosody
rbind_fill

rbind_fill
processAudio

Process audio
presets

Presets
plotUnrasterized

Plot unrasterized spetrogram
pseudoLog

Pseudolog
plotSpec

Plot spectrogram
reportTime

Report time
resample

Resample a vector
readAudio

Read audio
reverb

Reverb & echo
reformatAnchors

Reformat anchors
reportCI

Report CI
reformatFormants

Reformat formants
sampleModif

sampleModif
rnorm_truncated2

Random draw from a truncated normal distribution
rnorm_truncated

Random draw from a truncated normal distribution
scaleNoiseAnchors

Scale noise anchors
segment

Segment a sound
semitonesToHz

Convert semitones to Hz
shiftPitch

Shift pitch
schwa

Schwa-related formant conversion
shiftFormants

Shift formants
segmentManual

Manual counts of syllables in 260 sounds
scaleSPL

Scale SPL
silenceSegments

Silence sound segments
selfsim

Compute self-similarity
specToMS

Spectrogram to modulation spectrum
soundgen

Generate a sound
spreadSpec

Spread spectrum
soundgen_app

Interactive sound synthesizer
spectrogram

Spectrogram
sinc

Sinc
specToMS_1D

Spectrogram to modulation spectrum 1D
splitIntoChunks

Split vector into chunks
snake

Snake
splitContour

Split contour
timeSeriesSummary

Time series summary
ssm

Self-similarity matrix
transplantFormants

Transplant formants
timeStretch

Time stretch
transplantEnv

Transplant envelope
summarizeAnalyze

Summarize the output of analyze()
switchColorTheme

Switch color theme
updateAnalyze

Update analyze
upsampleGC

Upsample glottal cycles
to_dB

Convert to dB
wigglePars

Wiggle parameters
zeroOne

Normalize 0 to 1
validatePars

Validate parameters
writeAudio

Write audio
warpMatrix

Warp matrix
wiggleAnchors

Randomly modify anchors
wiggleGC

Wiggle glottal cycles