Learn R Programming

soundgen readme

R package for sound synthesis and acoustic analysis.
Homepage with help, demos, etc: http://cogsci.se/soundgen.html

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

814

Version

2.7.0

License

GPL (>= 2)

Maintainer

Last Published

September 11th, 2024

Functions in soundgen (2.7.0)

addVectors

Add overlapping vectors
analyze

Acoustic analysis
addFormants

Add formants
HzToNotes

Convert Hz to notes
addAM

Add amplitude modulation
addPitchCands

Plot pitch candidates
HzToSemitones

Convert Hz to semitones
Mode

Modified mode
HzToERB

Convert Hz to ERB rate
ERBToHz

Convert Hz to ERB rate
compareSounds

Compare two sounds
bandpass

Bandpass/stop filters
beat

Generate beat
convertStringToFormants

Prepare a list of formants
detectNLP

Detect NLP
crossFade

Join two waveforms by cross-fading
defaults_analyze_pitchCand

Defaults for plotting with analyze()
defaults

Shiny app defaults
clumper

Clump a sequence into large segments
costPerPath

Cost per path
defaults_analyze

Defaults and ranges for analyze()
audSpectrogram

Auditory spectrogram
annotation_app

Annotation app
checkInputType

Check audio input type
averageMatrices

Average matrices
convert_sec_to_hms

Print time
costJumps

Cost of jumps
.fade

Fade per sound
.audSpectrogram

Auditory spectrogram per sound
divideIntoSyllables

Syllable structure of a bout
detectNLP_training_synth

Nonlinear phenomena: Naive Bayes classifier trained on synthetic sounds
detectNLP_training_nonv

Nonlinear phenomena: Naive Bayes classifier trained on human nonverbal vocalizations
.addAM

Add AM to a sound
.detectNLP

Detect NLP per sound
.bandpass

Bandpass filter per sound
.filterSoundByMS

Filter a single sound by MS
.osc

Oscillogram per sound
.getLoudness

Loudness per sound
.getPitchZc

Zero-crossing rate per sound
.modulationSpectrum

Modulation spectrum per sound
.flatEnv

Flat envelope per sound
.analyze

Analyze per sound
analyzeFrame

Analyze fft frame
.getRMS

RMS amplitude per sound
def_form

Defaults and ranges for formant_app()
.getSurprisal

Get surprisal per sound
.ssm

SSM per sound
.spectrogram

Spectrogram per sound
.phasegram

Phasegram per sound
.shiftFormants

Shift formants per sound
.shiftPitch

Shift pitch per sound
filterMS

Filter modulation spectrum
fart

Fart
.pitchDescriptives

Pitch descriptives per file
fade

Fade
.prosody

Prosody per sound
dPhase

Phase derivatives
.timeStretch

Time stretch per sound
filled.contour.mod

Modified filled.contour
findInflections

Find inflections
drawContour

Draw contour
findJumps

Find frequency jumps
flatSpectrum

Flat spectrum
.resample

Resample per sound
forcePerPath

Force per path
flatEnv

Flat envelope / compressor
findZeroCrossing

Find zero crossing
filterSoundByMS

Filter sound by modulation spectrum
generateNoise

Generate noise
.addFormants

Add formants per sound
formant_app

Interactive formant tracker
gaussianSmooth2D

Gaussian smoothing in 2D
findBursts

Find bursts
findElbow

Find the elbow of a screeplot or similar
.getDuration

Get duration per sound
formatPitchManual

Format pitchManual
generateGC

Generate glottal cycles
findGrad

Find gradient
generateEpoch

Generate an epoch
.flatSpectrum

Flat spectrum per sound
getEntropy

Entropy
getEnv

Get amplitude envelope
getIntegerRandomWalk

Discrete random walk
generateHarmonics

Generate harmonics
getCheckerboardKernel

Checkerboard kernel
getDiscreteContour

Discrete smooth contour from anchors
getNovelty

SSM novelty
getFrameBank

Frame bank
.reverb

Add reverb to a sound
getPeakFreq

Get peak frequency
getFeatureFlux

Get flux from features
getFormantDispersion

Get formant dispersion
getFormants

Get formants
getCPP

Get Cepstral Peak Prominence
getAM_env

Get Amplitude Modulation
.segment

Internal soundgen function
generatePath

Generate path
findSyllables

Find syllables
getBandwidth

Get bandwidth
getLoudness

Get loudness
estimateVTL

Estimate vocal tract length
getSurprisal_vector

Get surprisal per vector
evaluatePars

Evaluate parameters for optimization
getSurprisal_matrix

Get surprisal per matrix
getSurprisal

Get surprisal
getPitchZc

Zero-crossing rate
getRMS

RMS amplitude
getPrior

Get prior for pitch candidates
findVoicedSegments

Find voiced segments
identifyAndPlay

Identify and play
hz2mel

Hz to mel
getSpectralFlux

Get spectral flux
getDom

Get lowest dominant frequency band
getRough

Calculate roughness from modulation spectrum
getRolloff

Control rolloff of harmonics
interpolMatrix

Interpolate matrix
harmEnergy

Energy in harmonics
getGlottalCycles

Divide f0 contour into glottal cycles
harmHeight

Height of harmonics
logit

Logit
interpolate

Interpolate
matchColumns

Match number of columns
matchPars

Match soundgen pars (experimental)
naiveBayes

Naive Bayes
naiveBayes_dynamicPrior

Naive Bayes dynamic prior
getRandomWalk

Random walk
matchLengths

Resize vector to required length
getHNR

Get HNR
getAM

Get amplitude modulation
isNeighbour_mod

Is neighbor modified
getPitchSpec

BaNa pitch tracker
getLoudnessPerFrame

Get loudness per frame
getPitchHps

Harmonic product spectrum
normalizeFolder

Normalize folder
modulationSpectrum

Modulation spectrum
getSpectralEnvelope

Spectral envelope
getVocalFry

Subharmonics
getDuration

Get duration
getVocalFry_per_epoch

Constant subharmonics regime
notesDict

Conversion table from Hz to musical notation
getSmoothSpectrum

Get smooth spectrum
guessPhase_GL

Guess phase GL
logistic

Logistic
istft_mod

Modified istft
guessPhase_spsi

Guess phase SPSI
medianSmoother

Median smoothing
iso226

iso226
getPitchCep

Cepstral pitch tracker
getPitchAutocor

Autocorrelation pitch tracker
pathfinder

Pathfinder
objectToString

Object to string
pitchManual

Manual pitch estimation in 260 sounds
notesToHz

Convert notes to Hz
optimizePars

Optimize parameters for acoustic analysis
harmHeight_peaks

Height of harmonics: peaks method
harmHeight_dif

Height of harmonics: difference method
osc

Oscillogram
naiveBayes_train

Train a naive Bayes classifier
pathfinding_fast

Path through pitch candidates: fast
htmlPlots

HTML for clickable plots
naiveBayes_likelihood

Naive Bayes likelihood
jet.col

Matlab colors
killDC

Kill DC
logWarpMS

Log-warp a modulation spectrum
isCentral.localMax

Simple peak detection
hillenbrand

Formants in American vowels
getMelSpec

Mel-transformed spectrogram
listDepth

List depth
morphList

Morph lists
morph

Morph sounds
lockToFormants

Lock to formants
noiseRemoval

Noise removal
morphFormants

Morph formants
morphDF

Morph dataframes
modulationSpectrumFragment

Modulation spectrum per fragment
pitchDescriptives

Pitch descriptives
phasegram

Phasegram
readAudio

Read audio
getSigmoid

Get sigmoid filter
msToSpec

Modulation spectrum to spectrogram
nonLinearPrediction_mod

Nonlinear prediction modified
prosody

Prosody
intplNA

Interpolate NAs
pathfinding_slow

Path through pitch candidates: slow
princarg

Principal argument
phasePropagate

Propagate phase
getSmoothContour

Smooth contour from anchors
pitchSmoothPraat

Pitch smoothing as in Praat
pitch_app

Interactive pitch tracker
invertSpectrogram

Invert spectrogram
spectrogram

Spectrogram
log01

log01
plotSpec

Plot spectrogram
processAudio

Process audio
nonlinPred

Nonlinear prediction
pseudoLog

Pseudolog
presets

Presets
schwa

Schwa-related formant conversion
reformatFormants

Reformat formants
logMatrix

Log-warp matrix
reportCI

Report CI
reportTime

Report time
shiftFormants

Shift formants
resample

Resample a vector
nonlinStats

Nonlinear statistics
scaleNoiseAnchors

Scale noise anchors
permittedValues

Defaults and ranges for soundgen()
scaleSPL

Scale SPL
reformatAnchors

Reformat anchors
snake

Snake
phon2sone

Convert phon to sone
pitchContour

Manually corrected pitch contours in 260 sounds
soundgen

Generate a sound
pDistr

Proportion of total
splitContour

Split contour
segment

Segment a sound
splitIntoChunks

Split vector into chunks
timeStretch

Time stretch
parabPeakInterpol

Parabolic peak interpolation
playme

Play audio
pseudoLog_undo

Undo pseudolog
subhToHarm

Subharmonics-to-harmonics ratio
sinc

Sinc
silenceSegments

Silence sound segments
plotMS

Plot modulation spectrum
segmentManual

Manual counts of syllables in 260 sounds
zeroOne

Normalize 0 to 1
sampleModif

sampleModif
to_dB

Convert to dB
soundgen_app

Interactive sound synthesizer
rnorm_truncated

Random draw from a truncated normal distribution
rbind_fill

rbind_fill
shiftPitch

Shift pitch
specToMS_1D

Spectrogram to modulation spectrum 1D
validatePars

Validate parameters
ssm

Self-similarity matrix
selfsim

Compute self-similarity
reverb

Reverb & echo
specToMS

Spectrogram to modulation spectrum
timeSeriesSummary

Time series summary
summarizeAnalyze

Summarize the output of analyze()
spreadSpec

Spread spectrum
transplantEnv

Transplant envelope
switchColorTheme

Switch color theme
transplantFormants

Transplant formants
wiggleAnchors

Randomly modify anchors
wiggleGC

Wiggle glottal cycles
warpMatrix

Warp matrix
semitonesToHz

Convert semitones to Hz
updateAnalyze

Update analyze
wigglePars

Wiggle parameters
upsampleGC

Upsample glottal cycles
writeAudio

Write audio