Learn R Programming

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

819

Version

2.4.0

License

GPL (>= 2)

Maintainer

Andrey Anikin

Last Published

October 16th, 2021

Functions in soundgen (2.4.0)

addPitchCands

Plot pitch candidates
HzToSemitones

Convert Hz to semitones
annotation_app

Annotation app
analyze

Acoustic analysis
addAM

Add amplitude modulation
addVectors

Add overlapping vectors
bandpass

Bandpass/stop filters
analyzeFolder

Analyze folder
analyzeFrame

Analyze fft frame
addFormants

Add formants
Mode

Modified mode
clumper

Clump a sequence into large segments
compareSounds

Compare two sounds
checkInputType

Check audio input type
defaults_analyze

Defaults and ranges for analyze()
defaults

Shiny app defaults
audSpectrogram

Auditory spectrogram
.addAM

Add AM to a sound
.addFormants

Add formants per sound
convertStringToFormants

Prepare a list of formants
averageMatrices

Average matrices
beat

Generate beat
dPhase

Phase derivatives
.getPitchZc

Zero-crossing rate per sound
.getRMS

RMS amplitude per sound
.getSurprisal

Get surprisal per sound
flatEnv

Flat envelope / compressor
filterMS

Filter modulation spectrum
flatSpectrum

Flat spectrum
filterSoundByMS

Filter sound by modulation spectrum
.modulationSpectrum

Modulation spectrum per sound
convert_sec_to_hms

Print time
.flatEnv

Flat envelope per sound
getGlottalCycles

Divide f0 contour into glottal cycles
getIntegerRandomWalk

Discrete random walk
getBandwidth

Get bandwidth
getCheckerboardKernel

Checkerboard kernel
getLoudnessPerFrame

Get loudness per frame
getMelSpec

Mel-transformed spectrogram
guessPhase_spsi

Guess phase SPSI
guessPhase_GL

Guess phase GL
def_form

Defaults and ranges for formant_app()
.bandpass

Bandpass filter per sound
defaults_analyze_pitchCand

Defaults for plotting with analyze()
.segment

Internal soundgen function
.filterSoundByMS

Filter a single sound by MS
costJumps

Cost of jumps
findGrad

Find gradient
divideIntoSyllables

Syllable structure of a bout
.flatSpectrum

Flat spectrum per sound
.analyze

Analyze per sound
.audSpectrogram

Auditory spectrogram per sound
findBursts

Find bursts
.shiftPitch

Shift pitch per sound
.spectrogram

Spectrogram per sound
generateHarmonics

Generate harmonics
.shiftFormants

Shift formants per sound
getFrameBank

Frame bank
generateNoise

Generate noise
crossFade

Join two waveforms by cross-fading
getFormantDispersion

Get formant dispersion
getSmoothSpectrum

Get smooth spectrum
getPitchCep

Cepstral pitch tracker
getPitchHps

Harmonic product spectrum
costPerPath

Cost per path
.getDuration

Get duration per sound
morphDF

Morph dataframes
getSpectralEnvelope

Spectral envelope
hz2mel

Hz to mel
morphFormants

Morph formants
.ssm

SSM per sound
normalizeFolder

Normalize folder
.resample

Resample per sound
.reverb

Add reverb to a sound
identifyAndPlay

Identify and play
getSurprisal_vector

Get surprisal per vector
getSurprisal_matrix

Get surprisal per matrix
pitchDescriptives

Pitch descriptives
notesDict

Conversion table from Hz to musical notation
estimateVTL

Estimate vocal tract length
findVoicedSegments

Find voiced segments
drawContour

Draw contour
evaluatePars

Evaluate parameters for optimization
osc

Oscillogram
log01

log01
fart

Fart
logMatrix

Log-warp matrix
.getLoudness

Loudness per sound
findZeroCrossing

Find zero crossing
.osc

Oscillogram per sound
pDistr

Proportion of total
pitchSmoothPraat

Pitch smoothing as in Praat
.pitchDescriptives

Pitch descriptives per file
filled.contour.mod

Modified filled.contour
fade

Fade
getLoudness

Get loudness
getPrior

Get prior for pitch candidates
getRMS

RMS amplitude
getDiscreteContour

Discrete smooth contour from anchors
formant_app

Interactive formant tracker
getLoudnessFolder

Get loudness folder
getDom

Get lowest dominant frequency band
forcePerPath

Force per path
pitch_app

Interactive pitch tracker
.timeStretch

Time stretch per sound
pitchManual

Manual pitch estimation in 260 sounds
gaussianSmooth2D

Gaussian smoothing in 2D
getEntropy

Entropy
getDuration

Get duration
getNovelty

SSM novelty
formatPitchManual

Format pitchManual
getPitchAutocor

Autocorrelation pitch tracker
processAudio

Process audio
generateEpoch

Generate an epoch
generateGC

Generate glottal cycles
getPitchZc

Zero-crossing rate
getPitchSpec

BaNa pitch tracker
findInflections

Find inflections
interpolate

Interpolate
getSurprisal

Get surprisal
getSpectralFlux

Get spectral flux
interpolMatrix

Interpolate matrix
generatePath

Generate path
findSyllables

Find syllables
getRMSFolder

Get RMS folder
rbind_fill

rbind_fill
getAM

Get amplitude modulation
getRandomWalk

Random walk
reformatFormants

Reformat formants
reportCI

Report CI
morphList

Morph lists
iso226

iso226
harmHeight_peaks

Height of harmonics: peaks method
isCentral.localMax

Simple peak detection
harmHeight_dif

Height of harmonics: difference method
getEnv

Get amplitude envelope
msToSpec

Modulation spectrum to spectrogram
objectToString

Object to string
schwa

Schwa-related formant conversion
scaleSPL

Scale SPL
getSmoothContour

Smooth contour from anchors
getVocalFry

Subharmonics
getVocalFry_per_epoch

Constant subharmonics regime
getSigmoid

Get sigmoid filter
optimizePars

Optimize parameters for acoustic analysis
hillenbrand

Formants in American vowels
shiftPitch

Shift pitch
to_dB

Convert to dB
silenceSegments

Silence sound segments
transplantFormants

Transplant formants
getFeatureFlux

Get flux from features
transplantEnv

Transplant envelope
updateAnalyze

Update analyze
matchColumns

Match number of columns
zeroOne

Normalize 0 to 1
permittedValues

Defaults and ranges for soundgen()
getRolloff

Control rolloff of harmonics
killDC

Kill DC
istft_mod

Modified istft
htmlPlots

HTML for clickable plots
matchLengths

Resize vector to required length
matchPars

Match soundgen pars (experimental)
getRough

Get roughness
phasePropagate

Propagate phase
modulationSpectrumFragment

Modulation spectrum per fragment
invertSpectrogram

Invert spectrogram
intplNA

Interpolate NAs
presets

Presets
harmHeight

Height of harmonics
harmEnergy

Energy in harmonics
medianSmoother

Median smoothing
pathfinding_fast

Path through pitch candidates: fast
listDepth

List depth
modulationSpectrum

Modulation spectrum
lockToFormants

Lock to formants
modulationSpectrumFolder

Modulation spectrum folder
princarg

Principal argument
phon2sone

Convert phon to sone
pitchContour

Manually corrected pitch contours in 260 sounds
sampleModif

sampleModif
pathfinding_slow

Path through pitch candidates: slow
readAudio

Read audio
segmentManual

Manual counts of syllables in 260 sounds
reformatAnchors

Reformat anchors
selfsim

Compute self-similarity
soundgen_app

Interactive sound synthesizer
specToMS

Spectrogram to modulation spectrum
scaleNoiseAnchors

Scale noise anchors
morph

Morph sounds
parabPeakInterpol

Parabolic peak interpolation
ssm

Self-similarity matrix
snake

Snake
subhToHarm

Subharmonics-to-harmonics ratio
wiggleGC

Wiggle glottal cycles
soundgen

Generate a sound
resample

Resample a vector
reportTime

Report time
segment

Segment a sound
wigglePars

Wiggle parameters
pathfinder

Pathfinder
splitContour

Split contour
playme

Play audio
upsampleGC

Upsample glottal cycles
spreadSpec

Spread spectrum
validatePars

Validate parameters
plotSpec

Plot spectrogram
segmentFolder

Segment folder
reverb

Reverb & echo
semitonesToHz

Convert semitones to Hz
rnorm_truncated

Random draw from a truncated normal distribution
spectrogram

Spectrogram
shiftFormants

Shift formants
spectrogramFolder

Spectrogram folder
timeSeriesSummary

Time series summary
summarizeAnalyze

Summarize the output of analyze()
switchColorTheme

Switch color theme
wiggleAnchors

Randomly modify anchors
timeStretch

Time stretch
warpMatrix

Warp matrix