Learn R Programming

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

R package for sound synthesis and acoustic analysis.
Homepage with help, demos, etc: http://cogsci.se/soundgen.html
Source code on github: https://github.com/tatters/soundgen

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): soundgen_app()
  • Acoustic analysis of a wav/mp3 file / folder: analyze() / analyzeFolder()
  • Shiny app for editing intonation contours (opens in a browser): pitch_app()
  • Shiny app for measuring formants (opens in a browser): formant_app()
  • Measuring syllables, pauses, and bursts in a wav/mp3 file / folder: segment() / segmentFolder

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, ylim = c(0, 6))
#> Scale not specified. Assuming that max amplitude is 1
a[1:5, c('pitch', 'peakFreq', 'harmHeight', 'HNR', 'ampl', 'loudness')]
#>      pitch peakFreq harmHeight       HNR      ampl  loudness
#> 1       NA       NA         NA        NA 0.0305833        NA
#> 2       NA 305.2747         NA  1.083205 0.1442435  9.636858
#> 3 300.0882 305.2747   1197.802 12.934929 0.3642711 17.808124
#> 4 299.4505 305.2747   1197.802 14.042033 0.5131389 22.289716
#> 5 296.0563 305.2747   1110.114 13.450248 0.4959925 22.193244
colnames(a)
#>  [1] "duration"           "duration_noSilence" "time"               "ampl"              
#>  [5] "amplVoiced"         "dom"                "entropy"            "f1_freq"           
#>  [9] "f1_width"           "f2_freq"            "f2_width"           "f3_freq"           
#> [13] "f3_width"           "harmEnergy"         "harmHeight"         "HNR"               
#> [17] "loudness"           "peakFreq"           "pitch"              "quartile25"        
#> [21] "quartile50"         "quartile75"         "specCentroid"       "specSlope"         
#> [25] "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 http://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

1.8.2

License

GPL (>= 2)

Maintainer

Andrey Anikin

Last Published

October 17th, 2020

Functions in soundgen (1.8.2)

addFormants

Add formants
addAM

Add amplitude modulation
beat

Generate beat
analyzeFrame

Analyze fft frame
compareSounds

Compare sounds (experimental)
analyzeFolder

Analyze folder
analyze

Analyze sound
clumper

Clump a sequence into large segments
crossFade

Join two waveforms by cross-fading
def_form

Defaults and ranges for formant_app()
Mode

Modified mode
HzToSemitones

Convert Hz to semitones
filterSoundByMS

Filter sound by modulation spectrum
fade

Fade
findBursts

Find bursts
fart

Fart
estimateVTL

Estimate vocal tract length
convert_sec_to_hms

Print time
convertStringToFormants

Prepare a list of formants
evaluatePars

Evaluate parameters for optimization
findVoicedSegments

Find voiced segments
filterMS

Filter modulation spectrum
filled.contour.mod

Modified filled.contour
addVectors

Add overlapping vectors
costPerPath

Cost per path
addPitchCands

Plot pitch candidates
costJumps

Cost of jumps
generateNoise

Generate noise
defaults_analyze

Defaults and ranges for analyze()
defaults

Shiny app defaults
downsample

Simple downsampling
drawContour

Draw contour
divideIntoSyllables

Syllable structure of a bout
generateEpoch

Generate an epoch
formant_app

Interactive formant tracker
gaussianSmooth2D

Gaussian smoothing in 2D
flatEnv

Flat envelope
flatSpectrum

Flat spectrum
forcePerPath

Force per path
defaults_analyze_pitchCand

Defaults for plotting with analyze()
getDiscreteContour

Discrete smooth contour from anchors
findZeroCrossing

Find zero crossing
getFormantDispersion

Get formant dispersion
findSyllables

Find syllables
findGrad

Find gradient
generateHarmonics

Generate harmonics
ftwindow_modif

Fourier transform windows (seewave)
getPitchSpec

BaNa pitch tracker
getBandwidth

Get bandwidth
getCheckerboardKernel

Checkerboard kernel
generateGC

Generate glottal cycles
getLoudness

Get loudness
generatePath

Generate path
getDom

Get lowest dominant frequency band
getGlottalCycles

Divide f0 contour into glottal cycles
getRMS

RMS amplitude per frame
getIntegerRandomWalk

Discrete random walk
getFrameBank

Frame bank
getMelSpec

Mel-transformed spectrum
getSmoothContour

Smooth contour from anchors
getRMSFolder

RMS amplitude per folder
getSmoothSpectrum

Get smooth spectrum
getLoudnessPerFrame

Get loudness per frame
getPrior

Get prior for pitch candidates
getVocalFry_per_epoch

Constant subharmonics regime
getEntropy

Entropy
gaussian.w

Gaussian window
getSpectralEnvelope

Spectral envelope
osc_dB

Oscillogram on a decibell scale
playme

Play audio
matchLengths

Resize vector to required length
guessPhase_spsi

Guess phase SPSI
matchPars

Match soundgen pars (experimental)
pDistr

Proportion of total
getVocalFry

Subharmonics
presets

Presets
harmEnergy

Energy in harmonics
getEnv

Get amplitude envelope
intplPitch

Interpolate pitch contour
medianSmoother

Median smoothing
isCentral.localMax

Simple peak detection
iso226

iso226
guessPhase_GL

Guess phase GL
getLoudnessFolder

Loudness per folder
reformatFormants

Reformat formants
getPitchCep

Cepstral pitch tracker
getPitchHps

Harmonic product spectrum
reformatAnchors

Reformat anchors
mergeSyllables

Merge syllables
getRough

Get roughness
harmHeight_peaks

Height of harmonics: peaks method
getPitchAutocor

Autocorrelation pitch tracker
getNovelty

SSM novelty
htmlPlots

HTML for clickable plots
interpolMatrix

Interpolate matrix
interpolate

Interpolate
getSigmoid

Get sigmoid filter
getRandomWalk

Random walk
getRolloff

Control rolloff of harmonics
harmHeight

Height of harmonics
harmHeight_dif

Height of harmonics: difference method
reportTime

Report time
reportCI

Report CI
logMatrix

Log-warp matrix
matchColumns

Match number of columns
splitContour

Split contour
snake

Snake
log01

log01
lockToFormants

Lock to formants
transplantFormants

Transplant formants
spreadSpec

Spread spectrum
transplantEnv

Transplant envelope
osc

Oscillogram
modulationSpectrumFolder

Modulation spectrum per folder
soundgen

Generate a sound
morph

Morph sounds
optimizePars

Optimize parameters for acoustic analysis
modulationSpectrum

Modulation spectrum
morphDF

Morph dataframes
notesDict

Conversion table from Hz to musical notation
objectToString

Object to string
wigglePars

Wiggle parameters
msToSpec

Modulation spectrum to spectrogram
pathfinding_fast

Path through pitch candidates: fast
invertSpectrogram

Invert spectrogram
normalizeFolder

Normalize folder
listDepth

List depth
killDC

Kill DC
upsample

Upsample pitch contour
updateAnalyze

Update analyze
pitchSmoothPraat

Pitch smoothing as in Praat
zeroOne

Normalize 0 to 1
morphFormants

Morph formants
morphList

Morph lists
segmentFolder

Segment all files in a folder
pathfinding_slow

Path through pitch candidates: slow
specToMS

Spectrogram to modulation spectrum
pitch_app

Interactive pitch tracker
sampleModif

sampleModif
soundgen_app

Interactive sound synthesizer
rnorm_truncated

Random draw from a truncated normal distribution
permittedValues

Defaults and ranges for soundgen()
segmentManual

Manual counts of syllables in 260 sounds
phon2sone

Convert phon to sone
spectrogram

Spectrogram
summarizeAnalyze

Summarize the output of analyze()
ssm

Self-similarity matrix
spectrogramFolder

Save spectrograms per folder
semitonesToHz

Convert semitones to Hz
scaleSPL

Scale SPL
validatePars

Validate parameters
scaleNoiseAnchors

Scale noise anchors
selfsim

Compute self-similarity
upsamplePitchContour

Upsample pitch contour
wiggleAnchors

Randomly modify anchors
wiggleGC

Wiggle glottal cycles
parabPeakInterpol

Parabolic peak interpolation
pathfinder

Pathfinder
pitchContour

Manually corrected pitch contours in 260 sounds
schwa

Schwa-related formant conversion
switchColorTheme

Switch color theme
segment

Segment a sound
to_dB

Convert to dB
pitchManual

Manual pitch estimation in 260 sounds