Learn R Programming

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

License

GPL (>= 2)

Maintainer

Andrey Anikin

Last Published

August 7th, 2021

Functions in soundgen (2.2.0)

bandpass

Bandpass/stop filters
.modulationSpectrum

Modulation spectrum per sound
.shiftPitch

Shift formants per sound
findSyllables

Find syllables
.spectrogram

Spectrogram per sound
findVoicedSegments

Find voiced segments
audSpectrogram

Auditory spectrogram
HzToSemitones

Convert Hz to semitones
flatSpectrum

Flat spectrum
beat

Generate beat
Mode

Modified mode
getEnv

Get amplitude envelope
forcePerPath

Force per path
checkInputType

Check audio input type
getFeatureFlux

Get flux from features
addFormants

Add formants
addAM

Add amplitude modulation
costJumps

Cost of jumps
divideIntoSyllables

Syllable structure of a bout
clumper

Clump a sequence into large segments
costPerPath

Cost per path
defaults_analyze

Defaults and ranges for analyze()
.addAM

Add AM to a sound
getLoudnessFolder

Get loudness folder
getRandomWalk

Random walk
getLoudness

Get loudness
defaults_analyze_pitchCand

Defaults for plotting with analyze()
.filterSoundByMS

Filter a single sound by MS
analyze

Acoustic analysis
drawContour

Draw contour
.flatEnv

Flat envelope per sound
.ssm

SSM per sound
compareSounds

Compare two sounds
getRolloff

Control rolloff of harmonics
crossFade

Join two waveforms by cross-fading
filled.contour.mod

Modified filled.contour
filterMS

Filter modulation spectrum
dPhase

Phase derivatives
.getLoudness

Loudness per sound
.flatSpectrum

Flat spectrum per sound
getLoudnessPerFrame

Get loudness per frame
getMelSpec

Mel-transformed spectrogram
msToSpec

Modulation spectrum to spectrogram
normalizeFolder

Normalize folder
analyzeFolder

Analyze folder
def_form

Defaults and ranges for formant_app()
getPrior

Get prior for pitch candidates
getVocalFry

Subharmonics
getPitchSpec

BaNa pitch tracker
fade

Fade
pitchDescriptives

Pitch descriptives
pDistr

Proportion of total
pitchContour

Manually corrected pitch contours in 260 sounds
parabPeakInterpol

Parabolic peak interpolation
reportCI

Report CI
defaults

Shiny app defaults
.audSpectrogram

Auditory spectrogram per sound
reportTime

Report time
getVocalFry_per_epoch

Constant subharmonics regime
htmlPlots

HTML for clickable plots
hillenbrand

Formants in American vowels
selfsim

Compute self-similarity
.bandpass

Bandpass filter per sound
findBursts

Find bursts
filterSoundByMS

Filter sound by modulation spectrum
semitonesToHz

Convert semitones to Hz
soundgen

Generate a sound
soundgen_app

Interactive sound synthesizer
.resample

Resample per sound
.reverb

Add reverb to a sound
generateGC

Generate glottal cycles
fart

Fart
zeroOne

Normalize 0 to 1
formant_app

Interactive formant tracker
addPitchCands

Plot pitch candidates
generateHarmonics

Generate harmonics
morphList

Morph lists
addVectors

Add overlapping vectors
pathfinder

Pathfinder
convertStringToFormants

Prepare a list of formants
.segment

Internal soundgen function
logMatrix

Log-warp matrix
matchColumns

Match number of columns
morphFormants

Morph formants
generateNoise

Generate noise
findZeroCrossing

Find zero crossing
.shiftFormants

Shift formants per sound
generatePath

Generate path
flatEnv

Flat envelope / compressor
getRMSFolder

Get RMS folder
getSpectralFlux

Get spectral flux
getRMS

RMS amplitude
getSpectralEnvelope

Spectral envelope
interpolMatrix

Interpolate matrix
identifyAndPlay

Identify and play
listDepth

List depth
.addFormants

Add formants per sound
convert_sec_to_hms

Print time
killDC

Kill DC
.analyze

Analyze per sound
getDom

Get lowest dominant frequency band
pathfinding_fast

Path through pitch candidates: fast
getEntropy

Entropy
getNovelty

SSM novelty
pitchManual

Manual pitch estimation in 260 sounds
modulationSpectrumFolder

Modulation spectrum folder
modulationSpectrumFragment

Modulation spectrum per fragment
pathfinding_slow

Path through pitch candidates: slow
estimateVTL

Estimate vocal tract length
.osc

Oscillogram per sound
plotSpec

Plot spectrogram
.pitchDescriptives

Pitch descriptives per file
permittedValues

Defaults and ranges for soundgen()
pitchSmoothPraat

Pitch smoothing as in Praat
rnorm_truncated

Random draw from a truncated normal distribution
getPitchAutocor

Autocorrelation pitch tracker
formatPitchManual

Format pitchManual
presets

Presets
guessPhase_GL

Guess phase GL
gaussianSmooth2D

Gaussian smoothing in 2D
findInflections

Find inflections
findGrad

Find gradient
evaluatePars

Evaluate parameters for optimization
sampleModif

sampleModif
guessPhase_spsi

Guess phase SPSI
reverb

Reverb & echo
resample

Resample a vector
segmentFolder

Segment folder
specToMS

Spectrogram to modulation spectrum
getCheckerboardKernel

Checkerboard kernel
spectrogram

Spectrogram
shiftFormants

Shift formants
segmentManual

Manual counts of syllables in 260 sounds
getDiscreteContour

Discrete smooth contour from anchors
summarizeAnalyze

Summarize the output of analyze()
subhToHarm

Subharmonics-to-harmonics ratio
getFrameBank

Frame bank
generateEpoch

Generate an epoch
getAM

Get amplitude modulation
getBandwidth

Get bandwidth
getRough

Get roughness
shiftPitch

Shift pitch
ssm

Self-similarity matrix
harmEnergy

Energy in harmonics
getFormantDispersion

Get formant dispersion
spreadSpec

Spread spectrum
getSigmoid

Get sigmoid filter
harmHeight

Height of harmonics
isCentral.localMax

Simple peak detection
invertSpectrogram

Invert spectrogram
lockToFormants

Lock to formants
log01

log01
medianSmoother

Median smoothing
istft_mod

Modified istft
harmHeight_peaks

Height of harmonics: peaks method
iso226

iso226
harmHeight_dif

Height of harmonics: difference method
morph

Morph sounds
notesDict

Conversion table from Hz to musical notation
morphDF

Morph dataframes
optimizePars

Optimize parameters for acoustic analysis
modulationSpectrum

Modulation spectrum
getGlottalCycles

Divide f0 contour into glottal cycles
getIntegerRandomWalk

Discrete random walk
pitch_app

Interactive pitch tracker
playme

Play audio
objectToString

Object to string
getPitchCep

Cepstral pitch tracker
osc

Oscillogram
reformatFormants

Reformat formants
reformatAnchors

Reformat anchors
scaleNoiseAnchors

Scale noise anchors
getSmoothContour

Smooth contour from anchors
scaleSPL

Scale SPL
getSmoothSpectrum

Get smooth spectrum
silenceSegments

Silence sound segments
getPitchHps

Harmonic product spectrum
interpolate

Interpolate
snake

Snake
timeSeriesSummary

Time series summary
switchColorTheme

Switch color theme
intplNA

Interpolate NAs
matchLengths

Resize vector to required length
phon2sone

Convert phon to sone
phasePropagate

Propagate phase
schwa

Schwa-related formant conversion
segment

Segment a sound
readAudio

Read audio
rbind_fill

rbind_fill
transplantEnv

Transplant envelope
upsampleGC

Upsample glottal cycles
wiggleGC

Wiggle glottal cycles
to_dB

Convert to dB
matchPars

Match soundgen pars (experimental)
validatePars

Validate parameters
wigglePars

Wiggle parameters
spectrogramFolder

Spectrogram folder
processAudio

Process audio
princarg

Principal argument
splitContour

Split contour
transplantFormants

Transplant formants
wiggleAnchors

Randomly modify anchors
updateAnalyze

Update analyze
warpMatrix

Warp matrix
analyzeFrame

Analyze fft frame
averageMatrices

Average matrices
.getRMS

RMS amplitude per sound