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

623

Version

2.5.1

License

GPL (>= 2)

Maintainer

Andrey Anikin

Last Published

February 10th, 2022

Functions in soundgen (2.5.1)

HzToSemitones

Convert Hz to semitones
ERBToHz

Convert Hz to ERB rate
analyze

Acoustic analysis
addAM

Add amplitude modulation
Mode

Modified mode
HzToERB

Convert Hz to ERB rate
addFormants

Add formants
HzToNotes

Convert Hz to notes
addVectors

Add overlapping vectors
addPitchCands

Plot pitch candidates
bandpass

Bandpass/stop filters
audSpectrogram

Auditory spectrogram
averageMatrices

Average matrices
convertStringToFormants

Prepare a list of formants
compareSounds

Compare two sounds
divideIntoSyllables

Syllable structure of a bout
defaults_analyze_pitchCand

Defaults for plotting with analyze()
crossFade

Join two waveforms by cross-fading
defaults

Shiny app defaults
defaults_analyze

Defaults and ranges for analyze()
.getDuration

Get duration per sound
clumper

Clump a sequence into large segments
checkInputType

Check audio input type
.flatSpectrum

Flat spectrum per sound
costPerPath

Cost per path
convert_sec_to_hms

Print time
.filterSoundByMS

Filter a single sound by MS
.flatEnv

Flat envelope per sound
.modulationSpectrum

Modulation spectrum per sound
beat

Generate beat
.osc

Oscillogram per sound
.analyze

Analyze per sound
.audSpectrogram

Auditory spectrogram per sound
.reverb

Add reverb to a sound
.getSurprisal

Get surprisal per sound
.resample

Resample per sound
analyzeFrame

Analyze fft frame
costJumps

Cost of jumps
.getRMS

RMS amplitude per sound
dPhase

Phase derivatives
annotation_app

Annotation app
def_form

Defaults and ranges for formant_app()
.getPitchZc

Zero-crossing rate per sound
.ssm

SSM per sound
.getLoudness

Loudness per sound
.timeStretch

Time stretch per sound
filterMS

Filter modulation spectrum
filterSoundByMS

Filter sound by modulation spectrum
estimateVTL

Estimate vocal tract length
drawContour

Draw contour
fart

Fart
.addFormants

Add formants per sound
.addAM

Add AM to a sound
evaluatePars

Evaluate parameters for optimization
.bandpass

Bandpass filter per sound
findZeroCrossing

Find zero crossing
.fade

Fade per sound
findVoicedSegments

Find voiced segments
generateNoise

Generate noise
generateHarmonics

Generate harmonics
.pitchDescriptives

Pitch descriptives per file
filled.contour.mod

Modified filled.contour
.spectrogram

Spectrogram per sound
.shiftPitch

Shift pitch per sound
fade

Fade
getDuration

Get duration
generateEpoch

Generate an epoch
generateGC

Generate glottal cycles
getEntropy

Entropy
findBursts

Find bursts
getCPP

Get Cepstral Peak Prominence
getCheckerboardKernel

Checkerboard kernel
findGrad

Find gradient
.prosody

Prosody per sound
findInflections

Find inflections
findSyllables

Find syllables
flatEnv

Flat envelope / compressor
flatSpectrum

Flat spectrum
generatePath

Generate path
formatPitchManual

Format pitchManual
.segment

Internal soundgen function
.shiftFormants

Shift formants per sound
gaussianSmooth2D

Gaussian smoothing in 2D
forcePerPath

Force per path
getAM

Get amplitude modulation
getGlottalCycles

Divide f0 contour into glottal cycles
formant_app

Interactive formant tracker
getDiscreteContour

Discrete smooth contour from anchors
getPrior

Get prior for pitch candidates
getRMS

RMS amplitude
getAM_env

Get Amplitude Modulation
getIntegerRandomWalk

Discrete random walk
getDom

Get lowest dominant frequency band
getBandwidth

Get bandwidth
getPitchCep

Cepstral pitch tracker
getPitchHps

Harmonic product spectrum
getSpectralEnvelope

Spectral envelope
getEnv

Get amplitude envelope
harmHeight

Height of harmonics
getSpectralFlux

Get spectral flux
getFeatureFlux

Get flux from features
getFormantDispersion

Get formant dispersion
getFrameBank

Frame bank
getPitchZc

Zero-crossing rate
getMelSpec

Mel-transformed spectrogram
getPitchSpec

BaNa pitch tracker
getSurprisal

Get surprisal
getSurprisal_matrix

Get surprisal per matrix
harmHeight_peaks

Height of harmonics: peaks method
guessPhase_spsi

Guess phase SPSI
getNovelty

SSM novelty
harmEnergy

Energy in harmonics
getLoudness

Get loudness
getVocalFry

Subharmonics
getSurprisal_vector

Get surprisal per vector
harmHeight_dif

Height of harmonics: difference method
getRandomWalk

Random walk
getLoudnessPerFrame

Get loudness per frame
killDC

Kill DC
getRolloff

Control rolloff of harmonics
listDepth

List depth
guessPhase_GL

Guess phase GL
getVocalFry_per_epoch

Constant subharmonics regime
hillenbrand

Formants in American vowels
intplNA

Interpolate NAs
interpolate

Interpolate
matchLengths

Resize vector to required length
getPitchAutocor

Autocorrelation pitch tracker
getPeakFreq

Get peak frequency
matchColumns

Match number of columns
logMatrix

Log-warp matrix
iso226

iso226
istft_mod

Modified istft
morphDF

Morph dataframes
morphFormants

Morph formants
matchPars

Match soundgen pars (experimental)
getSmoothContour

Smooth contour from anchors
msToSpec

Modulation spectrum to spectrogram
morphList

Morph lists
getRough

Get roughness
getSigmoid

Get sigmoid filter
normalizeFolder

Normalize folder
htmlPlots

HTML for clickable plots
getSmoothSpectrum

Get smooth spectrum
morph

Morph sounds
modulationSpectrumFragment

Modulation spectrum per fragment
notesToHz

Convert notes to Hz
invertSpectrogram

Invert spectrogram
hz2mel

Hz to mel
phon2sone

Convert phon to sone
phasePropagate

Propagate phase
notesDict

Conversion table from Hz to musical notation
objectToString

Object to string
isCentral.localMax

Simple peak detection
permittedValues

Defaults and ranges for soundgen()
pathfinding_slow

Path through pitch candidates: slow
pitch_app

Interactive pitch tracker
princarg

Principal argument
identifyAndPlay

Identify and play
interpolMatrix

Interpolate matrix
snake

Snake
processAudio

Process audio
silenceSegments

Silence sound segments
playme

Play audio
pitchManual

Manual pitch estimation in 260 sounds
pitchSmoothPraat

Pitch smoothing as in Praat
sampleModif

sampleModif
log01

log01
medianSmoother

Median smoothing
lockToFormants

Lock to formants
pathfinder

Pathfinder
pitchDescriptives

Pitch descriptives
pathfinding_fast

Path through pitch candidates: fast
pitchContour

Manually corrected pitch contours in 260 sounds
plotSpec

Plot spectrogram
optimizePars

Optimize parameters for acoustic analysis
modulationSpectrum

Modulation spectrum
osc

Oscillogram
reformatFormants

Reformat formants
scaleNoiseAnchors

Scale noise anchors
reportCI

Report CI
prosody

Prosody
presets

Presets
selfsim

Compute self-similarity
reverb

Reverb & echo
semitonesToHz

Convert semitones to Hz
rnorm_truncated

Random draw from a truncated normal distribution
rbind_fill

rbind_fill
spreadSpec

Spread spectrum
scaleSPL

Scale SPL
ssm

Self-similarity matrix
shiftFormants

Shift formants
readAudio

Read audio
schwa

Schwa-related formant conversion
shiftPitch

Shift pitch
timeStretch

Time stretch
to_dB

Convert to dB
wigglePars

Wiggle parameters
pDistr

Proportion of total
writeAudio

Write audio
parabPeakInterpol

Parabolic peak interpolation
reformatAnchors

Reformat anchors
subhToHarm

Subharmonics-to-harmonics ratio
summarizeAnalyze

Summarize the output of analyze()
timeSeriesSummary

Time series summary
switchColorTheme

Switch color theme
zeroOne

Normalize 0 to 1
reportTime

Report time
segment

Segment a sound
segmentManual

Manual counts of syllables in 260 sounds
soundgen_app

Interactive sound synthesizer
soundgen

Generate a sound
transplantEnv

Transplant envelope
transplantFormants

Transplant formants
spectrogram

Spectrogram
specToMS

Spectrogram to modulation spectrum
resample

Resample a vector
updateAnalyze

Update analyze
upsampleGC

Upsample glottal cycles
splitContour

Split contour
splitIntoChunks

Split vector into chunks
validatePars

Validate parameters
warpMatrix

Warp matrix
wiggleGC

Wiggle glottal cycles
wiggleAnchors

Randomly modify anchors