Learn R Programming

⚠️There's a newer version (2.7.3) 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

623

Version

2.6.1

License

GPL (>= 2)

Maintainer

Andrey Anikin

Last Published

September 29th, 2023

Functions in soundgen (2.6.1)

addVectors

Add overlapping vectors
addAM

Add amplitude modulation
ERBToHz

Convert Hz to ERB rate
HzToERB

Convert Hz to ERB rate
HzToSemitones

Convert Hz to semitones
beat

Generate beat
bandpass

Bandpass/stop filters
HzToNotes

Convert Hz to notes
addPitchCands

Plot pitch candidates
analyze

Acoustic analysis
annotation_app

Annotation app
analyzeFrame

Analyze fft frame
checkInputType

Check audio input type
dPhase

Phase derivatives
def_form

Defaults and ranges for formant_app()
defaults_analyze

Defaults and ranges for analyze()
.getLoudness

Loudness per sound
compareSounds

Compare two sounds
defaults_analyze_pitchCand

Defaults for plotting with analyze()
convertStringToFormants

Prepare a list of formants
convert_sec_to_hms

Print time
costJumps

Cost of jumps
averageMatrices

Average matrices
audSpectrogram

Auditory spectrogram
.shiftFormants

Shift formants per sound
.addAM

Add AM to a sound
divideIntoSyllables

Syllable structure of a bout
detectNLP

Detect NLP
.getPitchZc

Zero-crossing rate per sound
.shiftPitch

Shift pitch per sound
.analyze

Analyze per sound
.filterSoundByMS

Filter a single sound by MS
.addFormants

Add formants per sound
crossFade

Join two waveforms by cross-fading
clumper

Clump a sequence into large segments
defaults

Shiny app defaults
.detectNLP

Detect NLP per sound
.fade

Fade per sound
filled.contour.mod

Modified filled.contour
fade

Fade
.audSpectrogram

Auditory spectrogram per sound
.resample

Resample per sound
.prosody

Prosody per sound
.bandpass

Bandpass filter per sound
filterMS

Filter modulation spectrum
findVoicedSegments

Find voiced segments
findSyllables

Find syllables
costPerPath

Cost per path
.flatEnv

Flat envelope per sound
findGrad

Find gradient
findElbow

Find the elbow of a screeplot or similar
.getSurprisal

Get surprisal per sound
.getRMS

RMS amplitude per sound
detectNLP_training_nonv

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

Get amplitude modulation
fart

Fart
getAM_env

Get Amplitude Modulation
filterSoundByMS

Filter sound by modulation spectrum
findJumps

Find frequency jumps
formant_app

Interactive formant tracker
findInflections

Find inflections
detectNLP_training_synth

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

Get duration per sound
.spectrogram

Spectrogram per sound
.flatSpectrum

Flat spectrum per sound
findBursts

Find bursts
.ssm

SSM per sound
.phasegram

Phasegram per sound
generateNoise

Generate noise
.timeStretch

Time stretch per sound
generatePath

Generate path
.pitchDescriptives

Pitch descriptives per file
drawContour

Draw contour
formatPitchManual

Format pitchManual
getFeatureFlux

Get flux from features
getEntropy

Entropy
getEnv

Get amplitude envelope
flatEnv

Flat envelope / compressor
getBandwidth

Get bandwidth
getNovelty

SSM novelty
getMelSpec

Mel-transformed spectrogram
findZeroCrossing

Find zero crossing
getDiscreteContour

Discrete smooth contour from anchors
getCheckerboardKernel

Checkerboard kernel
getLoudness

Get loudness
flatSpectrum

Flat spectrum
gaussianSmooth2D

Gaussian smoothing in 2D
.modulationSpectrum

Modulation spectrum per sound
.osc

Oscillogram per sound
forcePerPath

Force per path
getCPP

Get Cepstral Peak Prominence
getFormantDispersion

Get formant dispersion
.reverb

Add reverb to a sound
getPitchZc

Zero-crossing rate
getPitchSpec

BaNa pitch tracker
identifyAndPlay

Identify and play
getLoudnessPerFrame

Get loudness per frame
getPeakFreq

Get peak frequency
generateEpoch

Generate an epoch
iso226

iso226
interpolMatrix

Interpolate matrix
modulationSpectrum

Modulation spectrum
matchPars

Match soundgen pars (experimental)
getVocalFry_per_epoch

Constant subharmonics regime
medianSmoother

Median smoothing
isNeighbour_mod

Is neighbor modified
getDom

Get lowest dominant frequency band
getPitchAutocor

Autocorrelation pitch tracker
naiveBayes_likelihood

Naive Bayes likelihood
naiveBayes_train

Train a naive Bayes classifier
optimizePars

Optimize parameters for acoustic analysis
killDC

Kill DC
objectToString

Object to string
harmHeight_dif

Height of harmonics: difference method
guessPhase_GL

Guess phase GL
matchLengths

Resize vector to required length
getRough

Get roughness
harmHeight

Height of harmonics
evaluatePars

Evaluate parameters for optimization
.segment

Internal soundgen function
estimateVTL

Estimate vocal tract length
getPrior

Get prior for pitch candidates
guessPhase_spsi

Guess phase SPSI
naiveBayes

Naive Bayes
getSpectralFlux

Get spectral flux
generateGC

Generate glottal cycles
getRolloff

Control rolloff of harmonics
getRandomWalk

Random walk
getIntegerRandomWalk

Discrete random walk
getSigmoid

Get sigmoid filter
getSurprisal_vector

Get surprisal per vector
getGlottalCycles

Divide f0 contour into glottal cycles
generateHarmonics

Generate harmonics
getSmoothContour

Smooth contour from anchors
pathfinder

Pathfinder
getSmoothSpectrum

Get smooth spectrum
getVocalFry

Subharmonics
getFormants

Get formants
pitchSmoothPraat

Pitch smoothing as in Praat
pseudoLog

Pseudolog
pitchManual

Manual pitch estimation in 260 sounds
pseudoLog_undo

Undo pseudolog
msToSpec

Modulation spectrum to spectrogram
morphList

Morph lists
phasegram

Phasegram
rbind_fill

rbind_fill
istft_mod

Modified istft
sampleModif

sampleModif
rnorm_truncated

Random draw from a truncated normal distribution
phon2sone

Convert phon to sone
shiftPitch

Shift pitch
soundgen

Generate a sound
schwa

Schwa-related formant conversion
readAudio

Read audio
snake

Snake
segment

Segment a sound
getDuration

Get duration
getFrameBank

Frame bank
getPitchCep

Cepstral pitch tracker
getRMS

RMS amplitude
soundgen_app

Interactive sound synthesizer
getPitchHps

Harmonic product spectrum
parabPeakInterpol

Parabolic peak interpolation
matchColumns

Match number of columns
pitchDescriptives

Pitch descriptives
nonLinearPrediction_mod

Nonlinear prediction modified
logit

Logit
getSpectralEnvelope

Spectral envelope
nonlinPred

Nonlinear prediction
scaleNoiseAnchors

Scale noise anchors
wiggleGC

Wiggle glottal cycles
pitch_app

Interactive pitch tracker
specToMS

Spectrogram to modulation spectrum
harmEnergy

Energy in harmonics
permittedValues

Defaults and ranges for soundgen()
lockToFormants

Lock to formants
processAudio

Process audio
hillenbrand

Formants in American vowels
harmHeight_peaks

Height of harmonics: peaks method
modulationSpectrumFragment

Modulation spectrum per fragment
phasePropagate

Propagate phase
segmentManual

Manual counts of syllables in 260 sounds
listDepth

List depth
getSurprisal

Get surprisal
summarizeAnalyze

Summarize the output of analyze()
switchColorTheme

Switch color theme
validatePars

Validate parameters
upsampleGC

Upsample glottal cycles
prosody

Prosody
pitchContour

Manually corrected pitch contours in 260 sounds
getSurprisal_matrix

Get surprisal per matrix
hz2mel

Hz to mel
htmlPlots

HTML for clickable plots
ssm

Self-similarity matrix
invertSpectrogram

Invert spectrogram
isCentral.localMax

Simple peak detection
morph

Morph sounds
notesToHz

Convert notes to Hz
notesDict

Conversion table from Hz to musical notation
timeSeriesSummary

Time series summary
logMatrix

Log-warp matrix
subhToHarm

Subharmonics-to-harmonics ratio
log01

log01
interpolate

Interpolate
osc

Oscillogram
intplNA

Interpolate NAs
reformatAnchors

Reformat anchors
normalizeFolder

Normalize folder
pDistr

Proportion of total
nonlinStats

Nonlinear statistics
logWarpMS

Log-warp a modulation spectrum
reformatFormants

Reformat formants
logistic

Logistic
morphDF

Morph dataframes
naiveBayes_dynamicPrior

Naive Bayes dynamic prior
resample

Resample a vector
scaleSPL

Scale SPL
transplantFormants

Transplant formants
wigglePars

Wiggle parameters
playme

Play audio
silenceSegments

Silence sound segments
updateAnalyze

Update analyze
warpMatrix

Warp matrix
morphFormants

Morph formants
spectrogram

Spectrogram
pathfinding_slow

Path through pitch candidates: slow
to_dB

Convert to dB
splitContour

Split contour
reverb

Reverb & echo
selfsim

Compute self-similarity
presets

Presets
princarg

Principal argument
splitIntoChunks

Split vector into chunks
pathfinding_fast

Path through pitch candidates: fast
transplantEnv

Transplant envelope
semitonesToHz

Convert semitones to Hz
timeStretch

Time stretch
plotMS

Plot modulation spectrum
plotSpec

Plot spectrogram
wiggleAnchors

Randomly modify anchors
reportTime

Report time
reportCI

Report CI
writeAudio

Write audio
shiftFormants

Shift formants
spreadSpec

Spread spectrum
zeroOne

Normalize 0 to 1
Mode

Modified mode
addFormants

Add formants