if (FALSE) {
# Objective: take formants from the bleating of a sheep and apply them to a
# synthetic sound with any arbitrary duration, intonation, nonlinearities etc
data(sheep, package = 'seewave') # import a recording from seewave
playme(sheep)
spectrogram(sheep, osc = TRUE)
recipient = soundgen(
sylLen = 1200,
pitch = c(100, 300, 250, 200),
vibratoFreq = 9, vibratoDep = 1,
addSilence = 180,
samplingRate = sheep@samp.rate, # same as donor
invalidArgAction = 'ignore') # force to keep the low samplingRate
playme(recipient, sheep@samp.rate)
spectrogram(recipient, sheep@samp.rate, osc = TRUE)
s1 = transplantFormants(
donor = sheep,
recipient = recipient,
samplingRate = sheep@samp.rate)
playme(s1, sheep@samp.rate)
spectrogram(s1, sheep@samp.rate, osc = TRUE)
# The spectral envelope of s1 will be similar to sheep's on a frequency scale
# determined by freqWindow. Compare the spectra:
par(mfrow = c(1, 2))
seewave::meanspec(sheep, dB = 'max0', alim = c(-50, 20), main = 'Donor')
seewave::meanspec(s1, f = sheep@samp.rate, dB = 'max0',
alim = c(-50, 20), main = 'Processed recipient')
par(mfrow = c(1, 1))
# if needed, transplant amplitude envelopes as well:
s2 = transplantEnv(donor = sheep, samplingRateD = sheep@samp.rate,
recipient = s1, windowLength = 10)
playme(s2, sheep@samp.rate)
spectrogram(s2, sheep@samp.rate, osc = TRUE)
# using "blur" to apply Gaussian blur to the donor's spectrogram instead of
# smoothing per frame with "freqWindow" (~2.5 times faster)
spectrogram(sheep, blur = c(150, 0)) # preview to select the amount of blur
s1b = transplantFormants(
donor = sheep,
recipient = recipient,
samplingRate = sheep@samp.rate,
freqWindow = 150,
blur = c(150, 0))
# blur: 150 = SD of 150 Hz along the frequency axis,
# 0 = no smoothing along the time axis
playme(s1b, sheep@samp.rate)
spectrogram(s1b, sheep@samp.rate, osc = TRUE)
# Now we use human formants on sheep source: the sheep asks "why?"
s3 = transplantFormants(
donor = getSpectralEnvelope(
nr = 512, nc = 100, # fairly arbitrary dimensions
formants = 'uaaai',
samplingRate = sheep@samp.rate),
recipient = sheep,
samplingRate = sheep@samp.rate)
playme(s3, sheep@samp.rate)
spectrogram(s3, sheep@samp.rate, osc = TRUE)
}
Run the code above in your browser using DataLab