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

623

Version

2.0.0

License

GPL (>= 2)

Maintainer

Andrey Anikin

Last Published

March 15th, 2021

Functions in soundgen (2.0.0)

addFormants

Add formants
Mode

Modified mode
analyzeFolder

Analyze folder
addAM

Add amplitude modulation
audSpectrogram

Auditory spectrogram
HzToSemitones

Convert Hz to semitones
addVectors

Add overlapping vectors
analyze

Acoustic analysis
addPitchCands

Plot pitch candidates
analyzeFrame

Analyze fft frame
averageMatrices

Average matrices
checkInputType

Check audio input type
convert_sec_to_hms

Print time
crossFade

Join two waveforms by cross-fading
costPerPath

Cost per path
beat

Generate beat
clumper

Clump a sequence into large segments
defaults_analyze

Defaults and ranges for analyze()
defaults_analyze_pitchCand

Defaults for plotting with analyze()
.audSpectrogram

Auditory spectrogram per sound
divideIntoSyllables

Syllable structure of a bout
.ssm

SSM per sound
.spectrogram

Spectrogram per sound
.flatEnv

Flat envelope per sound
.flatSpectrum

Flat spectrum per sound
filled.contour.mod

Modified filled.contour
.addAM

Add AM to a sound
.filterSoundByMS

Filter a single sound by MS
costJumps

Cost of jumps
filterMS

Filter modulation spectrum
compareSounds

Compare two sounds
convertStringToFormants

Prepare a list of formants
def_form

Defaults and ranges for formant_app()
forcePerPath

Force per path
.addFormants

Add formants per sound
generateEpoch

Generate an epoch
formant_app

Interactive formant tracker
.getLoudness

Loudness per sound
generateGC

Generate glottal cycles
defaults

Shiny app defaults
.analyze

Analyze per sound
.segment

Internal soundgen function
.reverb

Add reverb to a sound
.getRMS

RMS amplitude per sound
.osc

Oscillogram per sound
.modulationSpectrum

Modulation spectrum per sound
fade

Fade
fart

Fart
findGrad

Find gradient
findSyllables

Find syllables
getLoudnessFolder

Get loudness folder
getMelSpec

Mel-transformed spectrogram
getBandwidth

Get bandwidth
generatePath

Generate path
getNovelty

SSM novelty
estimateVTL

Estimate vocal tract length
getLoudnessPerFrame

Get loudness per frame
downsample

Simple downsampling
getPrior

Get prior for pitch candidates
evaluatePars

Evaluate parameters for optimization
drawContour

Draw contour
getRMS

RMS amplitude
getFrameBank

Frame bank
getGlottalCycles

Divide f0 contour into glottal cycles
getPitchHps

Harmonic product spectrum
getEntropy

Entropy
flatEnv

Flat envelope / compressor
flatSpectrum

Flat spectrum
getDom

Get lowest dominant frequency band
filterSoundByMS

Filter sound by modulation spectrum
findVoicedSegments

Find voiced segments
findZeroCrossing

Find zero crossing
getIntegerRandomWalk

Discrete random walk
generateHarmonics

Generate harmonics
generateNoise

Generate noise
findBursts

Find bursts
getSmoothSpectrum

Get smooth spectrum
formatPitchManual

Format pitchManual
getPitchSpec

BaNa pitch tracker
gaussianSmooth2D

Gaussian smoothing in 2D
getCheckerboardKernel

Checkerboard kernel
getRMSFolder

Get RMS folder
getRandomWalk

Random walk
getSigmoid

Get sigmoid filter
harmEnergy

Energy in harmonics
getSmoothContour

Smooth contour from anchors
getSpectralEnvelope

Spectral envelope
harmHeight

Height of harmonics
harmHeight_peaks

Height of harmonics: peaks method
harmHeight_dif

Height of harmonics: difference method
getLoudness

Get loudness
getRolloff

Control rolloff of harmonics
getRough

Get roughness
getDiscreteContour

Discrete smooth contour from anchors
interpolate

Interpolate
getEnv

Get amplitude envelope
getVocalFry

Subharmonics
intplPitch

Interpolate pitch contour
getVocalFry_per_epoch

Constant subharmonics regime
killDC

Kill DC
modulationSpectrumFolder

Modulation spectrum folder
modulationSpectrumFragment

Modulation spectrum per fragment
msToSpec

Modulation spectrum to spectrogram
listDepth

List depth
htmlPlots

HTML for clickable plots
normalizeFolder

Normalize folder
optimizePars

Optimize parameters for acoustic analysis
medianSmoother

Median smoothing
modulationSpectrum

Modulation spectrum
invertSpectrogram

Invert spectrogram
interpolMatrix

Interpolate matrix
logMatrix

Log-warp matrix
pathfinding_fast

Path through pitch candidates: fast
pathfinder

Pathfinder
matchColumns

Match number of columns
osc

Oscillogram
lockToFormants

Lock to formants
plotSpec

Plot spectrogram
getFormantDispersion

Get formant dispersion
ipa

Manually measured frequencies of the first four formants in 21 vowels from "Seeing Speech" (http://www.seeingspeech.ac.uk)
log01

log01
presets

Presets
morph

Morph sounds
objectToString

Object to string
notesDict

Conversion table from Hz to musical notation
morphDF

Morph dataframes
pDistr

Proportion of total
scaleSPL

Scale SPL
parabPeakInterpol

Parabolic peak interpolation
reverb

Reverb & echo
reformatFormants

Reformat formants
reformatAnchors

Reformat anchors
phon2sone

Convert phon to sone
rnorm_truncated

Random draw from a truncated normal distribution
pitchContour

Manually corrected pitch contours in 260 sounds
pitchManual

Manual pitch estimation in 260 sounds
soundgen_app

Interactive sound synthesizer
permittedValues

Defaults and ranges for soundgen()
pathfinding_slow

Path through pitch candidates: slow
pitch_app

Interactive pitch tracker
schwa

Schwa-related formant conversion
getPitchCep

Cepstral pitch tracker
getPitchAutocor

Autocorrelation pitch tracker
pitchSmoothPraat

Pitch smoothing as in Praat
spectrogramFolder

Spectrogram folder
spectrogram

Spectrogram
segment

Segment a sound
sampleModif

sampleModif
specToMS

Spectrogram to modulation spectrum
scaleNoiseAnchors

Scale noise anchors
playme

Play audio
segmentFolder

Segment folder
guessPhase_spsi

Guess phase SPSI
guessPhase_GL

Guess phase GL
zeroOne

Normalize 0 to 1
transplantFormants

Transplant formants
updateAnalyze

Update analyze
wiggleGC

Wiggle glottal cycles
wigglePars

Wiggle parameters
isCentral.localMax

Simple peak detection
iso226

iso226
semitonesToHz

Convert semitones to Hz
summarizeAnalyze

Summarize the output of analyze()
switchColorTheme

Switch color theme
segmentManual

Manual counts of syllables in 260 sounds
upsample

Upsample pitch contour
matchLengths

Resize vector to required length
morphFormants

Morph formants
matchPars

Match soundgen pars (experimental)
morphList

Morph lists
silenceSegments

Silence sound segments
processAudio

Process audio
splitContour

Split contour
readAudio

Read audio
selfsim

Compute self-similarity
upsamplePitchContour

Upsample pitch contour
spreadSpec

Spread spectrum
reportCI

Report CI
reportTime

Report time
transplantEnv

Transplant envelope
soundgen

Generate a sound
snake

Snake
to_dB

Convert to dB
ssm

Self-similarity matrix
subhToHarm

Subharmonics-to-harmonics ratio
wiggleAnchors

Randomly modify anchors
validatePars

Validate parameters