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.0

License

GPL (>= 2)

Maintainer

Andrey Anikin

Last Published

November 21st, 2021

Functions in soundgen (2.5.0)

Mode

Modified mode
HzToNotes

Convert Hz to notes
addPitchCands

Plot pitch candidates
addFormants

Add formants
addAM

Add amplitude modulation
HzToSemitones

Convert Hz to semitones
bandpass

Bandpass/stop filters
beat

Generate beat
HzToERB

Convert Hz to ERB rate
ERBToHz

Convert Hz to ERB rate
compareSounds

Compare two sounds
audSpectrogram

Auditory spectrogram
convertStringToFormants

Prepare a list of formants
.addAM

Add AM to a sound
.modulationSpectrum

Modulation spectrum per sound
.addFormants

Add formants per sound
.shiftFormants

Shift formants per sound
.osc

Oscillogram per sound
findZeroCrossing

Find zero crossing
findVoicedSegments

Find voiced segments
.segment

Internal soundgen function
averageMatrices

Average matrices
convert_sec_to_hms

Print time
flatEnv

Flat envelope / compressor
costJumps

Cost of jumps
checkInputType

Check audio input type
costPerPath

Cost per path
flatSpectrum

Flat spectrum
.audSpectrogram

Auditory spectrogram per sound
crossFade

Join two waveforms by cross-fading
.analyze

Analyze per sound
getCPP

Get Cepstral Peak Prominence
getLoudnessPerFrame

Get loudness per frame
getMelSpec

Mel-transformed spectrogram
getBandwidth

Get bandwidth
getPitchSpec

BaNa pitch tracker
clumper

Clump a sequence into large segments
dPhase

Phase derivatives
getPitchZc

Zero-crossing rate
.pitchDescriptives

Pitch descriptives per file
.prosody

Prosody per sound
.shiftPitch

Shift pitch per sound
harmHeight

Height of harmonics
findInflections

Find inflections
formatPitchManual

Format pitchManual
gaussianSmooth2D

Gaussian smoothing in 2D
.spectrogram

Spectrogram per sound
findSyllables

Find syllables
getEntropy

Entropy
harmHeight_dif

Height of harmonics: difference method
def_form

Defaults and ranges for formant_app()
getEnv

Get amplitude envelope
estimateVTL

Estimate vocal tract length
filled.contour.mod

Modified filled.contour
fart

Fart
getIntegerRandomWalk

Discrete random walk
drawContour

Draw contour
getLoudness

Get loudness
getAM

Get amplitude modulation
getFrameBank

Frame bank
generatePath

Generate path
getGlottalCycles

Divide f0 contour into glottal cycles
.filterSoundByMS

Filter a single sound by MS
iso226

iso226
getPitchCep

Cepstral pitch tracker
getSpectralFlux

Get spectral flux
getSpectralEnvelope

Spectral envelope
htmlPlots

HTML for clickable plots
getSurprisal

Get surprisal
getPitchHps

Harmonic product spectrum
getSurprisal_matrix

Get surprisal per matrix
guessPhase_spsi

Guess phase SPSI
istft_mod

Modified istft
morphDF

Morph dataframes
harmEnergy

Energy in harmonics
addVectors

Add overlapping vectors
hz2mel

Hz to mel
killDC

Kill DC
analyze

Acoustic analysis
matchPars

Match soundgen pars (experimental)
normalizeFolder

Normalize folder
matchLengths

Resize vector to required length
.resample

Resample per sound
.reverb

Add reverb to a sound
listDepth

List depth
.flatEnv

Flat envelope per sound
defaults

Shiny app defaults
defaults_analyze

Defaults and ranges for analyze()
notesDict

Conversion table from Hz to musical notation
.ssm

SSM per sound
modulationSpectrumFragment

Modulation spectrum per fragment
pitchSmoothPraat

Pitch smoothing as in Praat
pitch_app

Interactive pitch tracker
presets

Presets
.flatSpectrum

Flat spectrum per sound
.getLoudness

Loudness per sound
.timeStretch

Time stretch per sound
findBursts

Find bursts
findGrad

Find gradient
.getDuration

Get duration per sound
forcePerPath

Force per path
morph

Morph sounds
formant_app

Interactive formant tracker
osc

Oscillogram
getDom

Get lowest dominant frequency band
schwa

Schwa-related formant conversion
shiftPitch

Shift pitch
segment

Segment a sound
morphFormants

Morph formants
princarg

Principal argument
pDistr

Proportion of total
getDuration

Get duration
getFeatureFlux

Get flux from features
.getPitchZc

Zero-crossing rate per sound
timeSeriesSummary

Time series summary
pitchDescriptives

Pitch descriptives
prosody

Prosody
timeStretch

Time stretch
phasePropagate

Propagate phase
permittedValues

Defaults and ranges for soundgen()
warpMatrix

Warp matrix
silenceSegments

Silence sound segments
processAudio

Process audio
pitchManual

Manual pitch estimation in 260 sounds
soundgen_app

Interactive sound synthesizer
resample

Resample a vector
playme

Play audio
plotSpec

Plot spectrogram
specToMS

Spectrogram to modulation spectrum
filterMS

Filter modulation spectrum
filterSoundByMS

Filter sound by modulation spectrum
generateNoise

Generate noise
generateHarmonics

Generate harmonics
getFormantDispersion

Get formant dispersion
getCheckerboardKernel

Checkerboard kernel
wiggleAnchors

Randomly modify anchors
spectrogram

Spectrogram
getRandomWalk

Random walk
getDiscreteContour

Discrete smooth contour from anchors
shiftFormants

Shift formants
reverb

Reverb & echo
semitonesToHz

Convert semitones to Hz
splitContour

Split contour
getRough

Get roughness
transplantEnv

Transplant envelope
to_dB

Convert to dB
getVocalFry_per_epoch

Constant subharmonics regime
getSigmoid

Get sigmoid filter
annotation_app

Annotation app
divideIntoSyllables

Syllable structure of a bout
.bandpass

Bandpass filter per sound
analyzeFrame

Analyze fft frame
defaults_analyze_pitchCand

Defaults for plotting with analyze()
getRolloff

Control rolloff of harmonics
getSurprisal_vector

Get surprisal per vector
getVocalFry

Subharmonics
.fade

Fade per sound
switchColorTheme

Switch color theme
upsampleGC

Upsample glottal cycles
summarizeAnalyze

Summarize the output of analyze()
interpolMatrix

Interpolate matrix
identifyAndPlay

Identify and play
medianSmoother

Median smoothing
log01

log01
lockToFormants

Lock to formants
.getSurprisal

Get surprisal per sound
.getRMS

RMS amplitude per sound
guessPhase_GL

Guess phase GL
validatePars

Validate parameters
objectToString

Object to string
modulationSpectrum

Modulation spectrum
optimizePars

Optimize parameters for acoustic analysis
phon2sone

Convert phon to sone
hillenbrand

Formants in American vowels
harmHeight_peaks

Height of harmonics: peaks method
interpolate

Interpolate
intplNA

Interpolate NAs
msToSpec

Modulation spectrum to spectrogram
morphList

Morph lists
pathfinding_slow

Path through pitch candidates: slow
pathfinding_fast

Path through pitch candidates: fast
evaluatePars

Evaluate parameters for optimization
fade

Fade
getPitchAutocor

Autocorrelation pitch tracker
generateEpoch

Generate an epoch
getNovelty

SSM novelty
generateGC

Generate glottal cycles
pitchContour

Manually corrected pitch contours in 260 sounds
sampleModif

sampleModif
rnorm_truncated

Random draw from a truncated normal distribution
transplantFormants

Transplant formants
getPrior

Get prior for pitch candidates
getRMS

RMS amplitude
reformatFormants

Reformat formants
updateAnalyze

Update analyze
reportCI

Report CI
reformatAnchors

Reformat anchors
getSmoothContour

Smooth contour from anchors
getSmoothSpectrum

Get smooth spectrum
invertSpectrogram

Invert spectrogram
isCentral.localMax

Simple peak detection
logMatrix

Log-warp matrix
matchColumns

Match number of columns
reportTime

Report time
soundgen

Generate a sound
snake

Snake
parabPeakInterpol

Parabolic peak interpolation
rbind_fill

rbind_fill
pathfinder

Pathfinder
readAudio

Read audio
ssm

Self-similarity matrix
scaleNoiseAnchors

Scale noise anchors
segmentManual

Manual counts of syllables in 260 sounds
selfsim

Compute self-similarity
scaleSPL

Scale SPL
wigglePars

Wiggle parameters
wiggleGC

Wiggle glottal cycles
spreadSpec

Spread spectrum
writeAudio

Write audio
subhToHarm

Subharmonics-to-harmonics ratio
splitIntoChunks

Split vector into chunks
zeroOne

Normalize 0 to 1