AudioTimeStretch[audio,r]
applies time stretching to audio by the specified factor r.
AudioTimeStretch[video,r]
applies time stretching to the first audio track in video.
AudioTimeStretch
AudioTimeStretch[audio,r]
applies time stretching to audio by the specified factor r.
AudioTimeStretch[video,r]
applies time stretching to the first audio track in video.
Details and Options
- AudioTimeStretch stretches the input audio signal to the specified duration while preserving the pitch.
- The factor r can be any of the following:
-
r the duration will be multiplied by r Scaled[r] the duration will be multiplied by r Quantity[dur,unit] specifies the resulting duration dur in the given time unit - The following options are supported:
-
Method Automatic the method to use PartitionGranularity Automatic control the partitioning used for the computation of the short-time Fourier transform - By default, a phase vocoder algorithm is used. Use Method->"Speech" for time stretching speech signals.
Examples
open all close allBasic Examples (2)
Stretch audio by a factor of two:
a = \!\(\*AudioBox[""]\);
AudioTimeStretch[a, Scaled[2]]Plot the original and stretched audio:
AudioPlot[{a, %}]Stretch an Audio object to a full duration of 3 seconds:
a = \!\(\*AudioBox[""]\);
AudioTimeStretch[a, Quantity[3, "Seconds"]]Scope (3)
Stretch an Audio object by a factor of 2:
a = Import["ExampleData/rule30.wav"];
Duration[a]AudioTimeStretch[a, Scaled[2]]//DurationAudioTimeStretch alters the duration of complex sound without changing its timbre and pitch:
a = Mean[Table[AudioGenerator[{"Sin", 200 * i}, 2, SampleRate -> 8000] / i, {i, 1, 10}]]Stretch the audio object by a factor of 1.5:
res = AudioTimeStretch[a, 1.5]Periodogram[{a, res}, PlotRange -> {{0, 2000}, All}, ScalingFunctions -> "Absolute"]Process the audio track of a video:
AudioTimeStretch[\!\(\*VideoBox[""]\), 2]Options (4)
Method (1)
Use Method->"Speech" for speech signals to get a better quality result:
a = \!\(\*AudioBox[""]\);
AudioTimeStretch[a, 1.8, Method -> "Speech"]In comparison, the normal time stretching sounds less defined:
AudioTimeStretch[a, 1.8]PartitionGranularity (3)
Using a bigger partition size will improve the frequency response but will smear the transient components:
a = Import["ExampleData/rule30.wav"];
AudioTimeStretch[a, 1.1, PartitionGranularity -> Quantity[46, "Milliseconds"]]AudioTimeStretch[a, 1.1, PartitionGranularity -> Quantity[150, "Milliseconds"]]Using a small offset value will in general increase the quality of the result at the cost of more computation time:
a = Import["ExampleData/rule30.wav"];
AudioTimeStretch[a, 1.1, PartitionGranularity -> {Quantity[46, "Milliseconds"], Quantity[20, "Milliseconds"]}]//AbsoluteTimingAudioTimeStretch[a, 1.1, PartitionGranularity -> {Quantity[46, "Milliseconds"], Quantity[5, "Milliseconds"]}]//AbsoluteTimingBy default, HannWindow is used:
a = Import["ExampleData/rule30.wav"];
AudioTimeStretch[a, 1.1]Use Dirichlet window to perform no smoothing:
AudioTimeStretch[a, 1.1,
PartitionGranularity -> {Quantity[46, "Milliseconds"], Quantity[10, "Milliseconds"], DirichletWindow}]AudioTimeStretch[a, 1.1,
PartitionGranularity -> {Quantity[46, "Milliseconds"], Quantity[10, "Milliseconds"], BlackmanWindow}]Applications (1)
Change the duration of an audio object to match the duration of another one:
a1 = \!\(\*AudioBox[""]\);
a2 = ExampleData[{"Audio", "Piano"}];Duration /@ {a1, a2}Stretch the audio to match the duration of the target one:
AudioTimeStretch[a1, Duration[a2]]Duration[%]Properties & Relations (1)
Change the duration of a recording by using a different sample rate:
a = \!\(\*AudioBox[""]\);It will also affect the pitch:
Audio[a, SampleRate -> 11025]AudioTimeStretch does not alter the pitch:
AudioTimeStretch[a, 22050 / 11025]Possible Issues (2)
The quality of the result degrades with large stretch parameters:
AudioTimeStretch[\!\(\*AudioBox[""]\), 5.6]Using Method->"Speech" for non-speech signals may not lead to expected results:
a = \!\(\*AudioBox[""]\);
AudioTimeStretch[a, 1.8, Method -> "Speech"]Related Guides
Text
Wolfram Research (2016), AudioTimeStretch, Wolfram Language function, https://reference.wolfram.com/language/ref/AudioTimeStretch.html (updated 2024).
CMS
Wolfram Language. 2016. "AudioTimeStretch." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2024. https://reference.wolfram.com/language/ref/AudioTimeStretch.html.
APA
Wolfram Language. (2016). AudioTimeStretch. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/AudioTimeStretch.html
BibTeX
@misc{reference.wolfram_2026_audiotimestretch, author="Wolfram Research", title="{AudioTimeStretch}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/AudioTimeStretch.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_audiotimestretch, organization={Wolfram Research}, title={AudioTimeStretch}, year={2024}, url={https://reference.wolfram.com/language/ref/AudioTimeStretch.html}, note=[Accessed: 13-June-2026]}