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:

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

1,383

Version

2.7.2

License

GPL (>= 2)

Maintainer

Andrey Anikin

Last Published

January 22nd, 2025

Functions in soundgen (2.7.2)

Mode

Modified mode
HzToERB

Convert Hz to ERB rate
addFormants

Add formants
addPitchCands

Plot pitch candidates
addAM

Add amplitude modulation
checkInputType

Check audio input type
beat

Generate beat
annotation_app

Annotation app
convertStringToFormants

Prepare a list of formants
audSpectrogram

Auditory spectrogram
costJumps

Cost of jumps
bandpass

Bandpass/stop filters
averageMatrices

Average matrices
defaults

Shiny app defaults
def_form

Defaults and ranges for formant_app()
HzToSemitones

Convert Hz to semitones
HzToNotes

Convert Hz to notes
costPerPath

Cost per path
convert_sec_to_hms

Print time
detectNLP

Detect NLP
detectNLP_training_nonv

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

Acoustic analysis
analyzeFrame

Analyze fft frame
clumper

Clump a sequence into large segments
compareSounds

Compare two sounds
addVectors

Add overlapping vectors
addSubh_per_epoch

Constant subharmonics
defaults_analyze

Defaults and ranges for analyze()
defaults_analyze_pitchCand

Defaults for plotting with analyze()
.addAM

Add AM to a sound
.addFormants

Add formants per sound
.analyze

Analyze per sound
.getDuration

Get duration per sound
.getLoudness

Loudness per sound
.bandpass

Bandpass filter per sound
.audSpectrogram

Auditory spectrogram per sound
.getPitchZc

Zero-crossing rate per sound
.flatEnv

Flat envelope per sound
.osc

Oscillogram per sound
.flatSpectrum

Flat spectrum per sound
crossFade

Join two waveforms by cross-fading
.getRMS

RMS amplitude per sound
.detectNLP

Detect NLP per sound
.pitchDescriptives

Pitch descriptives per file
.prosody

Prosody per sound
estimateVTL

Estimate vocal tract length
drawContour

Draw contour
evaluatePars

Evaluate parameters for optimization
.phasegram

Phasegram per sound
.resample

Resample per sound
.timeStretch

Time stretch per sound
.reverb

Add reverb to a sound
drawFreqAxis

Draw frequency axis
.ssm

SSM per sound
filterSoundByMS

Filter sound by modulation spectrum
findBursts

Find bursts
filterMS

Filter modulation spectrum
detectNLP_training_synth

Nonlinear phenomena: Naive Bayes classifier trained on synthetic sounds
dPhase

Phase derivatives
filled.contour.mod

Modified filled.contour
getCheckerboardKernel

Checkerboard kernel
forcePerPath

Force per path
getCPP

Get Cepstral Peak Prominence
divideIntoSyllables

Syllable structure of a bout
findPeaks

Find peaks
.fade

Fade per sound
findSyllables

Find syllables
formant_app

Interactive formant tracker
.filterSoundByMS

Filter a single sound by MS
findVoicedSegments

Find voiced segments
generatePath

Generate path
getAM

Get amplitude modulation
findZeroCrossing

Find zero crossing
flatEnv

Flat envelope / compressor
getGlottalCycles

Divide f0 contour into glottal cycles
getNovelty

SSM novelty
getFrameBank

Frame bank
getPeakFreq

Get peak frequency
.segment

Internal soundgen function
.shiftFormants

Shift formants per sound
getSHR

Subharmonics-to-harmonics ratio
getLoudness

Get loudness
.shiftPitch

Shift pitch per sound
getSigmoid

Get sigmoid filter
getHNR

Get HNR
getIntegerRandomWalk

Discrete random walk
getMelSpec

Mel-transformed spectrogram
getRMS

RMS amplitude
interpolate

Interpolate
.getSurprisal

Get surprisal per sound
modulationSpectrum

Modulation spectrum
intplNA

Interpolate NAs
.modulationSpectrum

Modulation spectrum per sound
naiveBayes_train

Train a naive Bayes classifier
noiseRemoval

Noise removal
objectToString

Object to string
medianSmoother

Median smoothing
optimizePars

Optimize parameters for acoustic analysis
generateHarmonics

Generate harmonics
fade

Fade
.spectrogram

Spectrogram per sound
flatSpectrum

Flat spectrum
getRandomWalk

Random walk
harmHeight

Height of harmonics
fart

Fart
findJumps

Find frequency jumps
findInflections

Find inflections
findGrad

Find gradient
findElbow

Find the elbow of a screeplot or similar
reportTime

Report time
generateNoise

Generate noise
getPitchZc

Zero-crossing rate
harmHeight_dif

Height of harmonics: difference method
formatPitchManual

Format pitchManual
getFormantDispersion

Get formant dispersion
gaussianSmooth2D

Gaussian smoothing in 2D
getAM_env

Get Amplitude Modulation
getBandwidth

Get bandwidth
getFormants

Get formants
getPitchHps

Harmonic product spectrum
playme

Play audio
pitch_app

Interactive pitch tracker
sampleModif

sampleModif
generateEpoch

Generate an epoch
getPrior

Get prior for pitch candidates
getDuration

Get duration
getEntropy

Entropy
msToSpec

Modulation spectrum to spectrogram
parabPeakInterpol

Parabolic peak interpolation
logistic

Logistic
morphList

Morph lists
logWarpMS

Log-warp a modulation spectrum
generateGC

Generate glottal cycles
getDiscreteContour

Discrete smooth contour from anchors
pathfinder

Pathfinder
getPitchSpec

BaNa pitch tracker
getDom

Get lowest dominant frequency band
guessPhase_spsi

Guess phase SPSI
getRolloff

Control rolloff of harmonics
getSurprisal

Get surprisal
getRough

Calculate roughness from modulation spectrum
harmEnergy

Energy in harmonics
getSurprisal_matrix

Get surprisal per matrix
getPitchAutocor

Autocorrelation pitch tracker
htmlPlots

HTML for clickable plots
hz2mel

Hz to mel
getPitchCep

Cepstral pitch tracker
pitchContour

Manually corrected pitch contours in 260 sounds
logit

Logit
invertSpectrogram

Invert spectrogram
matchColumns

Match number of columns
pitchDescriptives

Pitch descriptives
princarg

Principal argument
wigglePars

Wiggle parameters
segmentManual

Manual counts of syllables in 260 sounds
ssm

Self-similarity matrix
getEnv

Get amplitude envelope
scaleSPL

Scale SPL
getFeatureFlux

Get flux from features
rnorm_truncated2

Random draw from a truncated normal distribution
processAudio

Process audio
scaleNoiseAnchors

Scale noise anchors
rbind_fill

rbind_fill
pseudoLog_undo

Undo pseudolog
resample

Resample a vector
soundgen

Generate a sound
selfsim

Compute self-similarity
writeAudio

Write audio
identifyAndPlay

Identify and play
naiveBayes

Naive Bayes
na.trim

Trim leading and trailing NAs
getSpectralEnvelope

Spectral envelope
jet.col

Matlab colors
getSpectralFlux

Get spectral flux
isNeighbour_mod

Is neighbor modified
permittedValues

Defaults and ranges for soundgen()
spectrogram

Spectrogram
soundgen_app

Interactive sound synthesizer
getSurprisal_vector

Get surprisal per vector
timeStretch

Time stretch
modulationSpectrumFragment

Modulation spectrum per fragment
morph

Morph sounds
getSmoothContour

Smooth contour from anchors
semitonesToHz

Convert semitones to Hz
killDC

Kill DC
nonlinPred

Nonlinear prediction
nonLinearPrediction_mod

Nonlinear prediction modified
splitContour

Split contour
wiggleGC

Wiggle glottal cycles
guessPhase_GL

Guess phase GL
summarizeAnalyze

Summarize the output of analyze()
pathfinding_slow

Path through pitch candidates: slow
pathfinding_fast

Path through pitch candidates: fast
snake

Snake
phasePropagate

Propagate phase
iso226

iso226
plotMS

Plot modulation spectrum
harmHeight_peaks

Height of harmonics: peaks method
to_dB

Convert to dB
notesToHz

Convert notes to Hz
plotSpec

Plot spectrogram
timeSeriesSummary

Time series summary
zeroOne

Normalize 0 to 1
notesDict

Conversion table from Hz to musical notation
shiftPitch

Shift pitch
naiveBayes_dynamicPrior

Naive Bayes dynamic prior
listDepth

List depth
istft_mod

Modified istft
reformatFormants

Reformat formants
reportCI

Report CI
getSmoothSpectrum

Get smooth spectrum
transplantEnv

Transplant envelope
matchPars

Match soundgen pars (experimental)
silenceSegments

Silence sound segments
pitchManual

Manual pitch estimation in 260 sounds
matchLengths

Resize vector to required length
lockToFormants

Lock to formants
hillenbrand

Formants in American vowels
switchColorTheme

Switch color theme
sinc

Sinc
wiggleAnchors

Randomly modify anchors
specToMS

Spectrogram to modulation spectrum
naiveBayes_likelihood

Naive Bayes likelihood
plotUnrasterized

Plot unrasterized spetrogram
presets

Presets
shiftFormants

Shift formants
prosody

Prosody
schwa

Schwa-related formant conversion
reverb

Reverb & echo
rnorm_truncated

Random draw from a truncated normal distribution
transplantFormants

Transplant formants
specToMS_1D

Spectrogram to modulation spectrum 1D
pitchSmoothPraat

Pitch smoothing as in Praat
osc

Oscillogram
segment

Segment a sound
log01

log01
interpolMatrix

Interpolate matrix
morphDF

Morph dataframes
warpMatrix

Warp matrix
pseudoLog

Pseudolog
logMatrix

Log-warp matrix
morphFormants

Morph formants
phasegram

Phasegram
normalizeFolder

Normalize folder
pDistr

Proportion of total
readAudio

Read audio
validatePars

Validate parameters
splitIntoChunks

Split vector into chunks
phon2sone

Convert phon to sone
upsampleGC

Upsample glottal cycles
nonlinStats

Nonlinear statistics
reformatAnchors

Reformat anchors
spreadSpec

Spread spectrum
updateAnalyze

Update analyze
addPitchJumps

Add pitch jumps
addSubh

Subharmonics
ERBToHz

Convert Hz to ERB rate