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
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): 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.5.2

License

GPL (>= 2)

Maintainer

Andrey Anikin

Last Published

August 14th, 2022

Functions in soundgen (2.5.2)

Mode

Modified mode
addVectors

Add overlapping vectors
HzToNotes

Convert Hz to notes
analyze

Acoustic analysis
.getRMS

RMS amplitude per sound
HzToSemitones

Convert Hz to semitones
.getSurprisal

Get surprisal per sound
addFormants

Add formants
addAM

Add amplitude modulation
addPitchCands

Plot pitch candidates
getLoudness

Get loudness
.segment

Internal soundgen function
compareSounds

Compare two sounds
getPitchCep

Cepstral pitch tracker
getLoudnessPerFrame

Get loudness per frame
.shiftFormants

Shift formants per sound
convertStringToFormants

Prepare a list of formants
audSpectrogram

Auditory spectrogram
averageMatrices

Average matrices
ERBToHz

Convert Hz to ERB rate
getPitchHps

Harmonic product spectrum
HzToERB

Convert Hz to ERB rate
.flatSpectrum

Flat spectrum per sound
defaults_analyze

Defaults and ranges for analyze()
defaults

Shiny app defaults
.getDuration

Get duration per sound
.modulationSpectrum

Modulation spectrum per sound
.osc

Oscillogram per sound
beat

Generate beat
bandpass

Bandpass/stop filters
annotation_app

Annotation app
analyzeFrame

Analyze fft frame
flatEnv

Flat envelope / compressor
.spectrogram

Spectrogram per sound
findGrad

Find gradient
defaults_analyze_pitchCand

Defaults for plotting with analyze()
dPhase

Phase derivatives
findBursts

Find bursts
.shiftPitch

Shift pitch per sound
flatSpectrum

Flat spectrum
getDiscreteContour

Discrete smooth contour from anchors
def_form

Defaults and ranges for formant_app()
convert_sec_to_hms

Print time
getDom

Get lowest dominant frequency band
.addFormants

Add formants per sound
.getLoudness

Loudness per sound
.addAM

Add AM to a sound
costJumps

Cost of jumps
getSurprisal

Get surprisal
.analyze

Analyze per sound
getSurprisal_matrix

Get surprisal per matrix
.audSpectrogram

Auditory spectrogram per sound
divideIntoSyllables

Syllable structure of a bout
estimateVTL

Estimate vocal tract length
guessPhase_spsi

Guess phase SPSI
.getPitchZc

Zero-crossing rate per sound
findVoicedSegments

Find voiced segments
drawContour

Draw contour
harmEnergy

Energy in harmonics
.prosody

Prosody per sound
.pitchDescriptives

Pitch descriptives per file
.bandpass

Bandpass filter per sound
getIntegerRandomWalk

Discrete random walk
getGlottalCycles

Divide f0 contour into glottal cycles
fart

Fart
.ssm

SSM per sound
.timeStretch

Time stretch per sound
identifyAndPlay

Identify and play
interpolMatrix

Interpolate matrix
phasePropagate

Propagate phase
morphList

Morph lists
getPeakFreq

Get peak frequency
presets

Presets
msToSpec

Modulation spectrum to spectrogram
plotSpec

Plot spectrogram
phon2sone

Convert phon to sone
checkInputType

Check audio input type
generateGC

Generate glottal cycles
formant_app

Interactive formant tracker
filled.contour.mod

Modified filled.contour
getAM_env

Get Amplitude Modulation
findZeroCrossing

Find zero crossing
generateEpoch

Generate an epoch
forcePerPath

Force per path
crossFade

Join two waveforms by cross-fading
clumper

Clump a sequence into large segments
costPerPath

Cost per path
getDuration

Get duration
getSurprisal_vector

Get surprisal per vector
getEntropy

Entropy
notesToHz

Convert notes to Hz
log01

log01
getVocalFry

Subharmonics
lockToFormants

Lock to formants
pDistr

Proportion of total
scaleNoiseAnchors

Scale noise anchors
sampleModif

sampleModif
objectToString

Object to string
parabPeakInterpol

Parabolic peak interpolation
prosody

Prosody
.reverb

Add reverb to a sound
findInflections

Find inflections
.resample

Resample per sound
.fade

Fade per sound
timeStretch

Time stretch
scaleSPL

Scale SPL
ssm

Self-similarity matrix
schwa

Schwa-related formant conversion
findSyllables

Find syllables
spreadSpec

Spread spectrum
rbind_fill

rbind_fill
transplantEnv

Transplant envelope
generateHarmonics

Generate harmonics
.filterSoundByMS

Filter a single sound by MS
getBandwidth

Get bandwidth
to_dB

Convert to dB
transplantFormants

Transplant formants
zeroOne

Normalize 0 to 1
generateNoise

Generate noise
getCheckerboardKernel

Checkerboard kernel
getCPP

Get Cepstral Peak Prominence
.flatEnv

Flat envelope per sound
getPrior

Get prior for pitch candidates
getRMS

RMS amplitude
getFrameBank

Frame bank
getFormantDispersion

Get formant dispersion
harmHeight_peaks

Height of harmonics: peaks method
getRough

Get roughness
getPitchAutocor

Autocorrelation pitch tracker
getSigmoid

Get sigmoid filter
getSmoothContour

Smooth contour from anchors
getMelSpec

Mel-transformed spectrogram
hillenbrand

Formants in American vowels
evaluatePars

Evaluate parameters for optimization
getSmoothSpectrum

Get smooth spectrum
iso226

iso226
fade

Fade
formatPitchManual

Format pitchManual
filterSoundByMS

Filter sound by modulation spectrum
gaussianSmooth2D

Gaussian smoothing in 2D
filterMS

Filter modulation spectrum
hz2mel

Hz to mel
htmlPlots

HTML for clickable plots
getNovelty

SSM novelty
killDC

Kill DC
getPitchZc

Zero-crossing rate
getPitchSpec

BaNa pitch tracker
generatePath

Generate path
getAM

Get amplitude modulation
istft_mod

Modified istft
medianSmoother

Median smoothing
harmHeight_dif

Height of harmonics: difference method
intplNA

Interpolate NAs
listDepth

List depth
interpolate

Interpolate
harmHeight

Height of harmonics
morphDF

Morph dataframes
modulationSpectrum

Modulation spectrum
readAudio

Read audio
morphFormants

Morph formants
logMatrix

Log-warp matrix
matchColumns

Match number of columns
matchLengths

Resize vector to required length
princarg

Principal argument
pathfinding_fast

Path through pitch candidates: fast
pathfinder

Pathfinder
processAudio

Process audio
matchPars

Match soundgen pars (experimental)
getEnv

Get amplitude envelope
getRolloff

Control rolloff of harmonics
getRandomWalk

Random walk
getSpectralEnvelope

Spectral envelope
getFeatureFlux

Get flux from features
segment

Segment a sound
reverb

Reverb & echo
rnorm_truncated

Random draw from a truncated normal distribution
segmentManual

Manual counts of syllables in 260 sounds
summarizeAnalyze

Summarize the output of analyze()
subhToHarm

Subharmonics-to-harmonics ratio
optimizePars

Optimize parameters for acoustic analysis
validatePars

Validate parameters
warpMatrix

Warp matrix
osc

Oscillogram
silenceSegments

Silence sound segments
snake

Snake
reformatAnchors

Reformat anchors
getSpectralFlux

Get spectral flux
pitchDescriptives

Pitch descriptives
pitchContour

Manually corrected pitch contours in 260 sounds
pitch_app

Interactive pitch tracker
playme

Play audio
reportCI

Report CI
reformatFormants

Reformat formants
shiftFormants

Shift formants
shiftPitch

Shift pitch
specToMS

Spectrogram to modulation spectrum
getVocalFry_per_epoch

Constant subharmonics regime
writeAudio

Write audio
wigglePars

Wiggle parameters
spectrogram

Spectrogram
wiggleGC

Wiggle glottal cycles
updateAnalyze

Update analyze
wiggleAnchors

Randomly modify anchors
splitIntoChunks

Split vector into chunks
upsampleGC

Upsample glottal cycles
splitContour

Split contour
guessPhase_GL

Guess phase GL
invertSpectrogram

Invert spectrogram
isCentral.localMax

Simple peak detection
normalizeFolder

Normalize folder
morph

Morph sounds
pathfinding_slow

Path through pitch candidates: slow
notesDict

Conversion table from Hz to musical notation
modulationSpectrumFragment

Modulation spectrum per fragment
pitchManual

Manual pitch estimation in 260 sounds
permittedValues

Defaults and ranges for soundgen()
pitchSmoothPraat

Pitch smoothing as in Praat
resample

Resample a vector
reportTime

Report time
selfsim

Compute self-similarity
soundgen_app

Interactive sound synthesizer
semitonesToHz

Convert semitones to Hz
switchColorTheme

Switch color theme
soundgen

Generate a sound
timeSeriesSummary

Time series summary