Learn R Programming

⚠️There's a newer version (2.7.2) of this package.Take me there.

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:

vignette("sound_generation", package="soundgen")

vignette("acoustic_analysis", package="soundgen")

Or, to open the vignettes in a browser:
RShowDoc('sound_generation', package = 'soundgen')

RShowDoc('acoustic_analysis', package = 'soundgen')

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

819

Version

2.6.3

License

GPL (>= 2)

Maintainer

Andrey Anikin

Last Published

May 28th, 2024

Functions in soundgen (2.6.3)

addPitchCands

Plot pitch candidates
HzToSemitones

Convert Hz to semitones
HzToNotes

Convert Hz to notes
addVectors

Add overlapping vectors
ERBToHz

Convert Hz to ERB rate
addAM

Add amplitude modulation
HzToERB

Convert Hz to ERB rate
addFormants

Add formants
analyze

Acoustic analysis
Mode

Modified mode
compareSounds

Compare two sounds
analyzeFrame

Analyze fft frame
annotation_app

Annotation app
bandpass

Bandpass/stop filters
beat

Generate beat
checkInputType

Check audio input type
defaults

Shiny app defaults
crossFade

Join two waveforms by cross-fading
costPerPath

Cost per path
clumper

Clump a sequence into large segments
defaults_analyze

Defaults and ranges for analyze()
costJumps

Cost of jumps
.detectNLP

Detect NLP per sound
convert_sec_to_hms

Print time
.fade

Fade per sound
convertStringToFormants

Prepare a list of formants
divideIntoSyllables

Syllable structure of a bout
detectNLP_training_nonv

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

Nonlinear phenomena: Naive Bayes classifier trained on synthetic sounds
dPhase

Phase derivatives
.addAM

Add AM to a sound
.filterSoundByMS

Filter a single sound by MS
def_form

Defaults and ranges for formant_app()
.audSpectrogram

Auditory spectrogram per sound
audSpectrogram

Auditory spectrogram
.bandpass

Bandpass filter per sound
.modulationSpectrum

Modulation spectrum per sound
.osc

Oscillogram per sound
.getRMS

RMS amplitude per sound
.getPitchZc

Zero-crossing rate per sound
.getLoudness

Loudness per sound
.prosody

Prosody per sound
.getSurprisal

Get surprisal per sound
.reverb

Add reverb to a sound
.segment

Internal soundgen function
.resample

Resample per sound
.phasegram

Phasegram per sound
averageMatrices

Average matrices
fart

Fart
fade

Fade
estimateVTL

Estimate vocal tract length
filled.contour.mod

Modified filled.contour
.pitchDescriptives

Pitch descriptives per file
findInflections

Find inflections
.timeStretch

Time stretch per sound
.spectrogram

Spectrogram per sound
findJumps

Find frequency jumps
filterMS

Filter modulation spectrum
defaults_analyze_pitchCand

Defaults for plotting with analyze()
.flatEnv

Flat envelope per sound
.ssm

SSM per sound
detectNLP

Detect NLP
formant_app

Interactive formant tracker
drawContour

Draw contour
findSyllables

Find syllables
findVoicedSegments

Find voiced segments
flatEnv

Flat envelope / compressor
.flatSpectrum

Flat spectrum per sound
.analyze

Analyze per sound
.getDuration

Get duration per sound
.addFormants

Add formants per sound
findZeroCrossing

Find zero crossing
getAM

Get amplitude modulation
generateNoise

Generate noise
evaluatePars

Evaluate parameters for optimization
getFeatureFlux

Get flux from features
getAM_env

Get Amplitude Modulation
findElbow

Find the elbow of a screeplot or similar
generatePath

Generate path
getFormantDispersion

Get formant dispersion
getDom

Get lowest dominant frequency band
getDuration

Get duration
getGlottalCycles

Divide f0 contour into glottal cycles
getRMS

RMS amplitude
getRandomWalk

Random walk
getHNR

Get HNR
getPitchZc

Zero-crossing rate
getPeakFreq

Get peak frequency
getNovelty

SSM novelty
.shiftFormants

Shift formants per sound
.shiftPitch

Shift pitch per sound
findGrad

Find gradient
formatPitchManual

Format pitchManual
filterSoundByMS

Filter sound by modulation spectrum
findBursts

Find bursts
gaussianSmooth2D

Gaussian smoothing in 2D
getCPP

Get Cepstral Peak Prominence
generateEpoch

Generate an epoch
getBandwidth

Get bandwidth
getPitchAutocor

Autocorrelation pitch tracker
getCheckerboardKernel

Checkerboard kernel
getFormants

Get formants
getDiscreteContour

Discrete smooth contour from anchors
harmEnergy

Energy in harmonics
getLoudnessPerFrame

Get loudness per frame
harmHeight

Height of harmonics
getPitchCep

Cepstral pitch tracker
getSurprisal_matrix

Get surprisal per matrix
interpolMatrix

Interpolate matrix
interpolate

Interpolate
getSurprisal_vector

Get surprisal per vector
harmHeight_dif

Height of harmonics: difference method
harmHeight_peaks

Height of harmonics: peaks method
getMelSpec

Mel-transformed spectrogram
lockToFormants

Lock to formants
invertSpectrogram

Invert spectrogram
intplNA

Interpolate NAs
logMatrix

Log-warp matrix
flatSpectrum

Flat spectrum
log01

log01
hillenbrand

Formants in American vowels
getVocalFry

Subharmonics
getVocalFry_per_epoch

Constant subharmonics regime
getFrameBank

Frame bank
getPrior

Get prior for pitch candidates
forcePerPath

Force per path
getSmoothSpectrum

Get smooth spectrum
htmlPlots

HTML for clickable plots
naiveBayes

Naive Bayes
msToSpec

Modulation spectrum to spectrogram
getPitchHps

Harmonic product spectrum
naiveBayes_dynamicPrior

Naive Bayes dynamic prior
logWarpMS

Log-warp a modulation spectrum
naiveBayes_likelihood

Naive Bayes likelihood
morphFormants

Morph formants
logit

Logit
logistic

Logistic
objectToString

Object to string
morphList

Morph lists
optimizePars

Optimize parameters for acoustic analysis
generateHarmonics

Generate harmonics
generateGC

Generate glottal cycles
naiveBayes_train

Train a naive Bayes classifier
getSpectralEnvelope

Spectral envelope
getEntropy

Entropy
phasegram

Phasegram
getEnv

Get amplitude envelope
permittedValues

Defaults and ranges for soundgen()
noiseRemoval

Noise removal
getIntegerRandomWalk

Discrete random walk
getPitchSpec

BaNa pitch tracker
phasePropagate

Propagate phase
getLoudness

Get loudness
phon2sone

Convert phon to sone
getRolloff

Control rolloff of harmonics
getSmoothContour

Smooth contour from anchors
isNeighbour_mod

Is neighbor modified
pitchContour

Manually corrected pitch contours in 260 sounds
guessPhase_spsi

Guess phase SPSI
isCentral.localMax

Simple peak detection
guessPhase_GL

Guess phase GL
getRough

Get roughness
pitchDescriptives

Pitch descriptives
pathfinding_fast

Path through pitch candidates: fast
getSigmoid

Get sigmoid filter
killDC

Kill DC
getSpectralFlux

Get spectral flux
listDepth

List depth
rbind_fill

rbind_fill
reportCI

Report CI
getSurprisal

Get surprisal
hz2mel

Hz to mel
identifyAndPlay

Identify and play
readAudio

Read audio
pathfinding_slow

Path through pitch candidates: slow
plotMS

Plot modulation spectrum
schwa

Schwa-related formant conversion
segment

Segment a sound
plotSpec

Plot spectrogram
reportTime

Report time
istft_mod

Modified istft
morph

Morph sounds
iso226

iso226
nonLinearPrediction_mod

Nonlinear prediction modified
matchColumns

Match number of columns
matchLengths

Resize vector to required length
morphDF

Morph dataframes
nonlinStats

Nonlinear statistics
normalizeFolder

Normalize folder
spectrogram

Spectrogram
specToMS

Spectrogram to modulation spectrum
osc

Oscillogram
pDistr

Proportion of total
pitchSmoothPraat

Pitch smoothing as in Praat
modulationSpectrum

Modulation spectrum
matchPars

Match soundgen pars (experimental)
pitchManual

Manual pitch estimation in 260 sounds
modulationSpectrumFragment

Modulation spectrum per fragment
medianSmoother

Median smoothing
reformatAnchors

Reformat anchors
wigglePars

Wiggle parameters
writeAudio

Write audio
sinc

Sinc
reverb

Reverb & echo
resample

Resample a vector
reformatFormants

Reformat formants
pitch_app

Interactive pitch tracker
notesToHz

Convert notes to Hz
notesDict

Conversion table from Hz to musical notation
playme

Play audio
processAudio

Process audio
scaleNoiseAnchors

Scale noise anchors
soundgen

Generate a sound
spreadSpec

Spread spectrum
soundgen_app

Interactive sound synthesizer
snake

Snake
prosody

Prosody
switchColorTheme

Switch color theme
timeSeriesSummary

Time series summary
wiggleGC

Wiggle glottal cycles
wiggleAnchors

Randomly modify anchors
nonlinPred

Nonlinear prediction
silenceSegments

Silence sound segments
shiftPitch

Shift pitch
parabPeakInterpol

Parabolic peak interpolation
pathfinder

Pathfinder
scaleSPL

Scale SPL
ssm

Self-similarity matrix
summarizeAnalyze

Summarize the output of analyze()
subhToHarm

Subharmonics-to-harmonics ratio
updateAnalyze

Update analyze
rnorm_truncated

Random draw from a truncated normal distribution
sampleModif

sampleModif
presets

Presets
princarg

Principal argument
pseudoLog_undo

Undo pseudolog
zeroOne

Normalize 0 to 1
segmentManual

Manual counts of syllables in 260 sounds
upsampleGC

Upsample glottal cycles
pseudoLog

Pseudolog
selfsim

Compute self-similarity
validatePars

Validate parameters
warpMatrix

Warp matrix
semitonesToHz

Convert semitones to Hz
timeStretch

Time stretch
to_dB

Convert to dB
splitIntoChunks

Split vector into chunks
transplantEnv

Transplant envelope
shiftFormants

Shift formants
splitContour

Split contour
transplantFormants

Transplant formants