| timeStretch | R Documentation |
Dynamically time-stretches a sound without preserving its pitch or formants,
as if gradually changing playback speed. Algorithm: the audio is resampled at
time-varying steps. This is about 100 times faster than time-stretching with
a phase vocoder in shiftPitch, but pitch and formants cannot be
preserved, and compressing the sound (stretch < 1) may cause artifacts due to
aliasing, since no anti-aliasing filter is applied (low-pass filter the input
and/or output if needed). The stretch contour is interpreted over the
output (stretched) duration, which is why the trajectory differs from
shiftPitch with the same anchors.
timeStretch(
x,
stretch = 1,
samplingRate = NULL,
interpol = "splineFC",
precision = 1000,
play = FALSE,
saveAudio = FALSE,
reportEvery = NULL,
cores = 1
)
x |
path to a folder, one or more wav or mp3 files c('file1.wav', 'file2.mp3'), Wave object, numeric vector, or a list of Wave objects or numeric vectors |
stretch |
1 = no change, >1 = longer, <1 = shorter. Single value, vector,
or anchor format (see |
samplingRate |
sampling rate of |
interpol |
interpolation method supported by |
precision |
the number of points used for estimating the duration of output (more = better, but slower) |
play |
if TRUE, plays the output audio using the default player on your
system. If a character string, it is passed to |
saveAudio |
if TRUE, saves the processed audio in a subdirectory named after the function and created in the input directory (if input is a file or folder) or in the working directory |
reportEvery |
when processing multiple inputs, report estimated time
left every |
cores |
number of cores for parallel processing |
The processed waveform as a numeric vector for a single input or a list for multiple outputs. The duration is approximate: the output may end up a few samples shorter than intended if the resampling trajectory reaches the end of the input.
shiftPitch
data(speechEx, package = 'soundgen') # import a recording
# playme(speechEx)
# spectrogram(speechEx)
s1 = timeStretch(speechEx, stretch = c(1, 3))
# playme(s1, speechEx@samp.rate)
# spectrogram(s1, speechEx@samp.rate)
# compare to a similar effect achieved with a phase vocoder in shiftPitch():
s2 = shiftPitch(
speechEx,
timeStretch = c(1, 3), # from 1 (original) to mult
multPitch = c(1, 1/3), # also drop pitch
multFormants = c(1, 1/3) # also drop formants (by the same proportion)
)
# playme(s2, speechEx@samp.rate)
# spectrogram(s2, speechEx@samp.rate)
# NB: because the two algorithms calculate transitions between stretch
# factors in different ways, the duration is not identical, even though the
# range of pitch change is the same
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.