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

652

Version

2.6.2

License

GPL (>= 2)

Maintainer

Andrey Anikin

Last Published

December 3rd, 2023

Functions in soundgen (2.6.2)

ERBToHz

Convert Hz to ERB rate
addAM

Add amplitude modulation
HzToNotes

Convert Hz to notes
addFormants

Add formants
addPitchCands

Plot pitch candidates
analyze

Acoustic analysis
HzToSemitones

Convert Hz to semitones
addVectors

Add overlapping vectors
HzToERB

Convert Hz to ERB rate
Mode

Modified mode
beat

Generate beat
clumper

Clump a sequence into large segments
bandpass

Bandpass/stop filters
audSpectrogram

Auditory spectrogram
compareSounds

Compare two sounds
averageMatrices

Average matrices
annotation_app

Annotation app
convertStringToFormants

Prepare a list of formants
checkInputType

Check audio input type
analyzeFrame

Analyze fft frame
detectNLP

Detect NLP
convert_sec_to_hms

Print time
costPerPath

Cost per path
defaults_analyze

Defaults and ranges for analyze()
dPhase

Phase derivatives
defaults_analyze_pitchCand

Defaults for plotting with analyze()
costJumps

Cost of jumps
defaults

Shiny app defaults
crossFade

Join two waveforms by cross-fading
.fade

Fade per sound
.addAM

Add AM to a sound
divideIntoSyllables

Syllable structure of a bout
.audSpectrogram

Auditory spectrogram per sound
def_form

Defaults and ranges for formant_app()
detectNLP_training_synth

Nonlinear phenomena: Naive Bayes classifier trained on synthetic sounds
.filterSoundByMS

Filter a single sound by MS
.getLoudness

Loudness per sound
.bandpass

Bandpass filter per sound
.flatSpectrum

Flat spectrum per sound
.getDuration

Get duration per sound
.detectNLP

Detect NLP per sound
detectNLP_training_nonv

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

RMS amplitude per sound
.modulationSpectrum

Modulation spectrum per sound
.analyze

Analyze per sound
.addFormants

Add formants per sound
.flatEnv

Flat envelope per sound
.shiftFormants

Shift formants per sound
.phasegram

Phasegram per sound
.osc

Oscillogram per sound
.getSurprisal

Get surprisal per sound
.segment

Internal soundgen function
.reverb

Add reverb to a sound
.pitchDescriptives

Pitch descriptives per file
.shiftPitch

Shift pitch per sound
filterMS

Filter modulation spectrum
drawContour

Draw contour
.prosody

Prosody per sound
.resample

Resample per sound
filterSoundByMS

Filter sound by modulation spectrum
estimateVTL

Estimate vocal tract length
.ssm

SSM per sound
.spectrogram

Spectrogram per sound
.timeStretch

Time stretch per sound
filled.contour.mod

Modified filled.contour
evaluatePars

Evaluate parameters for optimization
.getPitchZc

Zero-crossing rate per sound
fart

Fart
fade

Fade
findJumps

Find frequency jumps
findInflections

Find inflections
findElbow

Find the elbow of a screeplot or similar
findZeroCrossing

Find zero crossing
flatSpectrum

Flat spectrum
forcePerPath

Force per path
findBursts

Find bursts
flatEnv

Flat envelope / compressor
generateNoise

Generate noise
generatePath

Generate path
getDuration

Get duration
gaussianSmooth2D

Gaussian smoothing in 2D
generateEpoch

Generate an epoch
getFeatureFlux

Get flux from features
findGrad

Find gradient
generateHarmonics

Generate harmonics
getDom

Get lowest dominant frequency band
generateGC

Generate glottal cycles
findSyllables

Find syllables
findVoicedSegments

Find voiced segments
getCheckerboardKernel

Checkerboard kernel
getEntropy

Entropy
getFormantDispersion

Get formant dispersion
getMelSpec

Mel-transformed spectrogram
getAM_env

Get Amplitude Modulation
getPitchHps

Harmonic product spectrum
getLoudnessPerFrame

Get loudness per frame
getAM

Get amplitude modulation
getPitchSpec

BaNa pitch tracker
getPrior

Get prior for pitch candidates
getPitchZc

Zero-crossing rate
formant_app

Interactive formant tracker
getGlottalCycles

Divide f0 contour into glottal cycles
getDiscreteContour

Discrete smooth contour from anchors
getHNR

Get HNR
getEnv

Get amplitude envelope
getFrameBank

Frame bank
getFormants

Get formants
getPitchAutocor

Autocorrelation pitch tracker
getPitchCep

Cepstral pitch tracker
getSpectralFlux

Get spectral flux
getIntegerRandomWalk

Discrete random walk
getLoudness

Get loudness
getRMS

RMS amplitude
getVocalFry

Subharmonics
getBandwidth

Get bandwidth
formatPitchManual

Format pitchManual
getRandomWalk

Random walk
getCPP

Get Cepstral Peak Prominence
getPeakFreq

Get peak frequency
getNovelty

SSM novelty
harmHeight

Height of harmonics
getVocalFry_per_epoch

Constant subharmonics regime
harmEnergy

Energy in harmonics
interpolate

Interpolate
getSurprisal

Get surprisal
interpolMatrix

Interpolate matrix
getRolloff

Control rolloff of harmonics
getSigmoid

Get sigmoid filter
getSmoothContour

Smooth contour from anchors
hillenbrand

Formants in American vowels
getRough

Get roughness
htmlPlots

HTML for clickable plots
getSpectralEnvelope

Spectral envelope
getSurprisal_matrix

Get surprisal per matrix
logMatrix

Log-warp matrix
getSmoothSpectrum

Get smooth spectrum
morph

Morph sounds
morphList

Morph lists
morphFormants

Morph formants
iso226

iso226
log01

log01
morphDF

Morph dataframes
istft_mod

Modified istft
logWarpMS

Log-warp a modulation spectrum
lockToFormants

Lock to formants
hz2mel

Hz to mel
guessPhase_GL

Guess phase GL
msToSpec

Modulation spectrum to spectrogram
getSurprisal_vector

Get surprisal per vector
invertSpectrogram

Invert spectrogram
notesToHz

Convert notes to Hz
nonlinPred

Nonlinear prediction
matchColumns

Match number of columns
objectToString

Object to string
identifyAndPlay

Identify and play
intplNA

Interpolate NAs
matchLengths

Resize vector to required length
naiveBayes

Naive Bayes
normalizeFolder

Normalize folder
naiveBayes_train

Train a naive Bayes classifier
nonLinearPrediction_mod

Nonlinear prediction modified
naiveBayes_dynamicPrior

Naive Bayes dynamic prior
listDepth

List depth
pathfinding_slow

Path through pitch candidates: slow
guessPhase_spsi

Guess phase SPSI
logistic

Logistic
logit

Logit
naiveBayes_likelihood

Naive Bayes likelihood
killDC

Kill DC
nonlinStats

Nonlinear statistics
pitch_app

Interactive pitch tracker
pitchSmoothPraat

Pitch smoothing as in Praat
optimizePars

Optimize parameters for acoustic analysis
phasePropagate

Propagate phase
readAudio

Read audio
pitchDescriptives

Pitch descriptives
matchPars

Match soundgen pars (experimental)
modulationSpectrum

Modulation spectrum
harmHeight_peaks

Height of harmonics: peaks method
isNeighbour_mod

Is neighbor modified
reformatAnchors

Reformat anchors
pitchManual

Manual pitch estimation in 260 sounds
permittedValues

Defaults and ranges for soundgen()
phasegram

Phasegram
osc

Oscillogram
princarg

Principal argument
medianSmoother

Median smoothing
phon2sone

Convert phon to sone
pitchContour

Manually corrected pitch contours in 260 sounds
isCentral.localMax

Simple peak detection
modulationSpectrumFragment

Modulation spectrum per fragment
harmHeight_dif

Height of harmonics: difference method
plotSpec

Plot spectrogram
pDistr

Proportion of total
parabPeakInterpol

Parabolic peak interpolation
presets

Presets
prosody

Prosody
pseudoLog_undo

Undo pseudolog
schwa

Schwa-related formant conversion
selfsim

Compute self-similarity
scaleSPL

Scale SPL
pseudoLog

Pseudolog
rbind_fill

rbind_fill
semitonesToHz

Convert semitones to Hz
soundgen

Generate a sound
snake

Snake
reformatFormants

Reformat formants
reportCI

Report CI
processAudio

Process audio
sampleModif

sampleModif
reverb

Reverb & echo
transplantEnv

Transplant envelope
sinc

Sinc
wiggleGC

Wiggle glottal cycles
rnorm_truncated

Random draw from a truncated normal distribution
notesDict

Conversion table from Hz to musical notation
to_dB

Convert to dB
silenceSegments

Silence sound segments
transplantFormants

Transplant formants
spectrogram

Spectrogram
wigglePars

Wiggle parameters
scaleNoiseAnchors

Scale noise anchors
ssm

Self-similarity matrix
subhToHarm

Subharmonics-to-harmonics ratio
pathfinder

Pathfinder
updateAnalyze

Update analyze
playme

Play audio
plotMS

Plot modulation spectrum
writeAudio

Write audio
pathfinding_fast

Path through pitch candidates: fast
wiggleAnchors

Randomly modify anchors
warpMatrix

Warp matrix
splitContour

Split contour
spreadSpec

Spread spectrum
zeroOne

Normalize 0 to 1
splitIntoChunks

Split vector into chunks
shiftFormants

Shift formants
shiftPitch

Shift pitch
segment

Segment a sound
resample

Resample a vector
reportTime

Report time
switchColorTheme

Switch color theme
summarizeAnalyze

Summarize the output of analyze()
upsampleGC

Upsample glottal cycles
validatePars

Validate parameters
soundgen_app

Interactive sound synthesizer
segmentManual

Manual counts of syllables in 260 sounds
timeSeriesSummary

Time series summary
timeStretch

Time stretch
specToMS

Spectrogram to modulation spectrum