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, 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.02638271       NA
#> 2 295.1621 300.1361   296.6386  5.621424 0.15939804 10.50662
#> 3 296.6386 300.1361   593.2772 13.417414 0.36515952 18.01119
#> 4 296.4598 300.1361  1185.8392 13.250932 0.47913904 23.01556
#> 5 292.8389 300.1361  1231.4125 11.141331 0.45389806 22.25239
colnames(a)
#> NULL

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

License

GPL (>= 2)

Maintainer

Andrey Anikin

Last Published

September 6th, 2021

Functions in soundgen (2.3.0)

Mode

Modified mode
addVectors

Add overlapping vectors
addAM

Add amplitude modulation
audSpectrogram

Auditory spectrogram
HzToSemitones

Convert Hz to semitones
addFormants

Add formants
analyze

Acoustic analysis
analyzeFolder

Analyze folder
addPitchCands

Plot pitch candidates
analyzeFrame

Analyze fft frame
averageMatrices

Average matrices
costPerPath

Cost per path
costJumps

Cost of jumps
convertStringToFormants

Prepare a list of formants
.analyze

Analyze per sound
convert_sec_to_hms

Print time
.addFormants

Add formants per sound
compareSounds

Compare two sounds
defaults_analyze_pitchCand

Defaults for plotting with analyze()
defaults_analyze

Defaults and ranges for analyze()
clumper

Clump a sequence into large segments
.getSurprisal

Get surprisal per sound
.flatSpectrum

Flat spectrum per sound
beat

Generate beat
.addAM

Add AM to a sound
.getPitchZc

Zero-crossing rate per sound
divideIntoSyllables

Syllable structure of a bout
.bandpass

Bandpass filter per sound
.audSpectrogram

Auditory spectrogram per sound
fade

Fade
defaults

Shiny app defaults
.shiftPitch

Shift formants per sound
.spectrogram

Spectrogram per sound
def_form

Defaults and ranges for formant_app()
checkInputType

Check audio input type
.ssm

SSM per sound
drawContour

Draw contour
.getRMS

RMS amplitude per sound
findSyllables

Find syllables
.getLoudness

Loudness per sound
.segment

Internal soundgen function
.shiftFormants

Shift formants per sound
crossFade

Join two waveforms by cross-fading
bandpass

Bandpass/stop filters
.modulationSpectrum

Modulation spectrum per sound
findGrad

Find gradient
getLoudnessPerFrame

Get loudness per frame
findVoicedSegments

Find voiced segments
getMelSpec

Mel-transformed spectrogram
dPhase

Phase derivatives
flatSpectrum

Flat spectrum
getCheckerboardKernel

Checkerboard kernel
fart

Fart
.resample

Resample per sound
forcePerPath

Force per path
getDiscreteContour

Discrete smooth contour from anchors
getPitchZc

Zero-crossing rate
getPitchSpec

BaNa pitch tracker
filterMS

Filter modulation spectrum
generateGC

Generate glottal cycles
filled.contour.mod

Modified filled.contour
getEnv

Get amplitude envelope
getFeatureFlux

Get flux from features
getFormantDispersion

Get formant dispersion
getFrameBank

Frame bank
generateHarmonics

Generate harmonics
gaussianSmooth2D

Gaussian smoothing in 2D
findInflections

Find inflections
getPrior

Get prior for pitch candidates
getSurprisal

Get surprisal
getSpectralFlux

Get spectral flux
estimateVTL

Estimate vocal tract length
.reverb

Add reverb to a sound
formant_app

Interactive formant tracker
istft_mod

Modified istft
getSigmoid

Get sigmoid filter
evaluatePars

Evaluate parameters for optimization
getSmoothContour

Smooth contour from anchors
killDC

Kill DC
getDom

Get lowest dominant frequency band
generateEpoch

Generate an epoch
getRMS

RMS amplitude
getPitchCep

Cepstral pitch tracker
getLoudness

Get loudness
getSpectralEnvelope

Spectral envelope
getEntropy

Entropy
getSmoothSpectrum

Get smooth spectrum
hillenbrand

Formants in American vowels
getPitchHps

Harmonic product spectrum
getLoudnessFolder

Get loudness folder
matchColumns

Match number of columns
formatPitchManual

Format pitchManual
getSurprisal_matrix

Get surprisal per matrix
listDepth

List depth
optimizePars

Optimize parameters for acoustic analysis
objectToString

Object to string
htmlPlots

HTML for clickable plots
lockToFormants

Lock to formants
generateNoise

Generate noise
harmEnergy

Energy in harmonics
getNovelty

SSM novelty
getPitchAutocor

Autocorrelation pitch tracker
generatePath

Generate path
getSurprisal_vector

Get surprisal per vector
guessPhase_GL

Guess phase GL
matchLengths

Resize vector to required length
pitchSmoothPraat

Pitch smoothing as in Praat
pitch_app

Interactive pitch tracker
phon2sone

Convert phon to sone
morph

Morph sounds
pitchContour

Manually corrected pitch contours in 260 sounds
.flatEnv

Flat envelope per sound
modulationSpectrumFragment

Modulation spectrum per fragment
.filterSoundByMS

Filter a single sound by MS
intplNA

Interpolate NAs
harmHeight

Height of harmonics
.osc

Oscillogram per sound
guessPhase_spsi

Guess phase SPSI
morphDF

Morph dataframes
hz2mel

Hz to mel
pitchDescriptives

Pitch descriptives
identifyAndPlay

Identify and play
segmentManual

Manual counts of syllables in 260 sounds
morphFormants

Morph formants
filterSoundByMS

Filter sound by modulation spectrum
pitchManual

Manual pitch estimation in 260 sounds
.pitchDescriptives

Pitch descriptives per file
selfsim

Compute self-similarity
findZeroCrossing

Find zero crossing
pathfinding_fast

Path through pitch candidates: fast
findBursts

Find bursts
getVocalFry_per_epoch

Constant subharmonics regime
pathfinding_slow

Path through pitch candidates: slow
getVocalFry

Subharmonics
playme

Play audio
validatePars

Validate parameters
sampleModif

sampleModif
plotSpec

Plot spectrogram
flatEnv

Flat envelope / compressor
getBandwidth

Get bandwidth
getAM

Get amplitude modulation
warpMatrix

Warp matrix
wiggleAnchors

Randomly modify anchors
modulationSpectrum

Modulation spectrum
invertSpectrogram

Invert spectrogram
matchPars

Match soundgen pars (experimental)
isCentral.localMax

Simple peak detection
getIntegerRandomWalk

Discrete random walk
iso226

iso226
getGlottalCycles

Divide f0 contour into glottal cycles
wiggleGC

Wiggle glottal cycles
medianSmoother

Median smoothing
scaleNoiseAnchors

Scale noise anchors
schwa

Schwa-related formant conversion
scaleSPL

Scale SPL
splitContour

Split contour
modulationSpectrumFolder

Modulation spectrum folder
normalizeFolder

Normalize folder
reverb

Reverb & echo
snake

Snake
rnorm_truncated

Random draw from a truncated normal distribution
soundgen

Generate a sound
getRMSFolder

Get RMS folder
getRandomWalk

Random walk
getRolloff

Control rolloff of harmonics
spreadSpec

Spread spectrum
osc

Oscillogram
to_dB

Convert to dB
getRough

Get roughness
timeSeriesSummary

Time series summary
pDistr

Proportion of total
harmHeight_dif

Height of harmonics: difference method
presets

Presets
summarizeAnalyze

Summarize the output of analyze()
switchColorTheme

Switch color theme
notesDict

Conversion table from Hz to musical notation
phasePropagate

Propagate phase
reportCI

Report CI
permittedValues

Defaults and ranges for soundgen()
shiftPitch

Shift pitch
readAudio

Read audio
princarg

Principal argument
reformatFormants

Reformat formants
reformatAnchors

Reformat anchors
silenceSegments

Silence sound segments
harmHeight_peaks

Height of harmonics: peaks method
segment

Segment a sound
interpolate

Interpolate
interpolMatrix

Interpolate matrix
ssm

Self-similarity matrix
logMatrix

Log-warp matrix
msToSpec

Modulation spectrum to spectrogram
morphList

Morph lists
parabPeakInterpol

Parabolic peak interpolation
log01

log01
pathfinder

Pathfinder
specToMS

Spectrogram to modulation spectrum
soundgen_app

Interactive sound synthesizer
segmentFolder

Segment folder
updateAnalyze

Update analyze
processAudio

Process audio
upsampleGC

Upsample glottal cycles
subhToHarm

Subharmonics-to-harmonics ratio
zeroOne

Normalize 0 to 1
wigglePars

Wiggle parameters
rbind_fill

rbind_fill
shiftFormants

Shift formants
resample

Resample a vector
semitonesToHz

Convert semitones to Hz
reportTime

Report time
transplantEnv

Transplant envelope
spectrogramFolder

Spectrogram folder
spectrogram

Spectrogram
transplantFormants

Transplant formants