# NOT RUN {
# 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
donor = as.numeric(scale(sheep@left)) # source of formants
samplingRate = sheep@samp.rate
playme(donor, samplingRate)
spectrogram(donor, samplingRate, osc = TRUE)
seewave::meanspec(donor, f = samplingRate, dB = 'max0')
recipient = soundgen(sylLen = 1200,
pitch = c(100, 300, 250, 200),
vibratoFreq = 9, vibratoDep = 1,
addSilence = 180,
samplingRate = samplingRate,
invalidArgAction = 'ignore') # keep low samplingRate
playme(recipient, samplingRate)
spectrogram(recipient, samplingRate, osc = TRUE)
s1 = transplantFormants(
donor = donor,
recipient = recipient,
samplingRate = samplingRate)
playme(s1, samplingRate)
spectrogram(s1, samplingRate, osc = TRUE)
seewave::meanspec(s1, f = samplingRate, dB = 'max0')
# if needed, transplant amplitude envelopes as well:
s2 = transplantEnv(donor = donor, samplingRateD = samplingRate,
recipient = s1, windowLength = 10)
playme(s2, samplingRate)
spectrogram(s2, samplingRate, osc = TRUE)
# Now we use human formants on sheep source: the sheep says "why?"
s2 = transplantFormants(
donor = soundgen(formants = 'uaaai',
samplingRate = samplingRate,
invalidArgAction = 'ignore'),
recipient = donor,
samplingRate = samplingRate)
playme(s2, samplingRate)
spectrogram(s2, samplingRate, osc = TRUE)
seewave::meanspec(s2, f = samplingRate, dB = 'max0')
# We can also transplant synthetic formants w/o synthesizing a donor sound to
# save time
s3 = transplantFormants(
donor = getSpectralEnvelope(
nr = 512, nc = 100, # fairly arbitrary dimensions
formants = 'uaaai',
samplingRate = samplingRate),
recipient = donor,
samplingRate = samplingRate)
playme(s3, samplingRate)
spectrogram(s3, samplingRate, osc = TRUE)
# }
Run the code above in your browser using DataLab