---
title: "AudioTimeStretch"
language: "en"
type: "Symbol"
summary: "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."
keywords: 
- time stretching
- audio time stretching
- time stretch
- pitch shift
- phase vocoder
- fast forward
- fast audio
- slow audio
- slow down audio
- slower audio
- change audio speed
- change audio duration
- audio time scaling
canonical_url: "https://reference.wolfram.com/language/ref/AudioTimeStretch.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Audio Editing"
    link: "https://reference.wolfram.com/language/guide/AudioEditing.en.md"
  - 
    title: "Speech Computation"
    link: "https://reference.wolfram.com/language/guide/SpeechComputation.en.md"
  - 
    title: "Video Computation: Update History"
    link: "https://reference.wolfram.com/language/guide/VideoComputation-UpdateHistory.en.md"
related_functions: 
  - 
    title: "AudioPitchShift"
    link: "https://reference.wolfram.com/language/ref/AudioPitchShift.en.md"
  - 
    title: "AudioFrequencyShift"
    link: "https://reference.wolfram.com/language/ref/AudioFrequencyShift.en.md"
  - 
    title: "AudioTrackApply"
    link: "https://reference.wolfram.com/language/ref/AudioTrackApply.en.md"
  - 
    title: "VideoTimeStretch"
    link: "https://reference.wolfram.com/language/ref/VideoTimeStretch.en.md"
  - 
    title: "AudioResample"
    link: "https://reference.wolfram.com/language/ref/AudioResample.en.md"
  - 
    title: "Duration"
    link: "https://reference.wolfram.com/language/ref/Duration.en.md"
---
# 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.

[image]

* 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 (13)

### Basic Examples (2)

Stretch audio by a factor of two:

```wl
In[1]:=
a = \!\(\*AudioBox["![Embedded Audio Player](audio://content-ctqtq)"]\);
AudioTimeStretch[a, Scaled[2]]

Out[1]= \!\(\*AudioBox["![Embedded Audio Player](audio://content-4egay)"]\)
```

Plot the original and stretched audio:

```wl
In[2]:= AudioPlot[{a, %}]

Out[2]= [image]
```

---

Stretch an ``Audio`` object to a full duration of 3 seconds:

```wl
In[1]:=
a = \!\(\*AudioBox["![Embedded Audio Player](audio://content-ctqtq)"]\);
AudioTimeStretch[a, Quantity[3, "Seconds"]]

Out[1]= \!\(\*AudioBox["![Embedded Audio Player](audio://content-odxyl)"]\)
```

### Scope (3)

Stretch an ``Audio`` object by a factor of 2:

```wl
In[1]:=
a = Import["ExampleData/rule30.wav"];
Duration[a]

Out[1]= Quantity[1.8, "Seconds"]

In[2]:= AudioTimeStretch[a, Scaled[2]]//Duration

Out[2]= Quantity[3.6, "Seconds"]
```

---

``AudioTimeStretch`` alters the duration of complex sound without changing its timbre and pitch:

```wl
In[1]:= a = Mean[Table[AudioGenerator[{"Sin", 200 * i}, 2, SampleRate -> 8000] / i, {i, 1, 10}]]

Out[1]= \!\(\*AudioBox["![Embedded Audio Player](audio://content-6ninl)"]\)
```

Stretch the audio object by a factor of 1.5:

```wl
In[2]:= res = AudioTimeStretch[a, 1.5]

Out[2]= \!\(\*AudioBox["![Embedded Audio Player](audio://content-mapgu)"]\)

In[3]:= Periodogram[{a, res}, PlotRange -> {{0, 2000}, All}, ScalingFunctions -> "Absolute"]

Out[3]= [image]
```

---

Process the audio track of a video:

```wl
In[1]:= AudioTimeStretch[\!\(\*VideoBox["![Video Player: ExampleData/fish.mp4](video://content-2sfji)"]\), 2]

Out[1]= \!\(\*VideoBox["![Embedded Video Player](video://content-en7o4)"]\)
```

### Options (4)

#### Method (1)

Use ``Method -> "Speech"`` for speech signals to get a better quality result:

```wl
In[1]:=
a = \!\(\*AudioBox["![Embedded Audio Player](audio://content-2pcu3)"]\);
AudioTimeStretch[a, 1.8, Method -> "Speech"]

Out[1]= \!\(\*AudioBox["![Embedded Audio Player](audio://content-wt1s9)"]\)
```

In comparison, the normal time stretching sounds less defined:

```wl
In[2]:= AudioTimeStretch[a, 1.8]

Out[2]= \!\(\*AudioBox["![Embedded Audio Player](audio://content-8p98f)"]\)
```

#### PartitionGranularity (3)

Using a bigger partition size will improve the frequency response but will smear the transient components:

```wl
In[1]:=
a = Import["ExampleData/rule30.wav"];
AudioTimeStretch[a, 1.1, PartitionGranularity -> Quantity[46, "Milliseconds"]]

Out[1]= \!\(\*AudioBox["![Embedded Audio Player](audio://content-oe5e0)"]\)

In[2]:= AudioTimeStretch[a, 1.1, PartitionGranularity -> Quantity[150, "Milliseconds"]]

Out[2]= \!\(\*AudioBox["![Embedded Audio Player](audio://content-zkvyi)"]\)
```

---

Using a small offset value will in general increase the quality of the result at the cost of more computation time:

```wl
In[1]:=
a = Import["ExampleData/rule30.wav"];
AudioTimeStretch[a, 1.1, PartitionGranularity -> {Quantity[46, "Milliseconds"], Quantity[20, "Milliseconds"]}]//AbsoluteTiming

Out[1]= {0.009293, \!\(\*AudioBox["![Embedded Audio Player](audio://content-c1f4y)"]\)}

In[2]:= AudioTimeStretch[a, 1.1, PartitionGranularity -> {Quantity[46, "Milliseconds"], Quantity[5, "Milliseconds"]}]//AbsoluteTiming

Out[2]= {0.035262, \!\(\*AudioBox["![Embedded Audio Player](audio://content-cg0yu)"]\)}
```

---

By default, ``HannWindow`` is used:

```wl
In[1]:=
a = Import["ExampleData/rule30.wav"];
AudioTimeStretch[a, 1.1]

Out[1]= \!\(\*AudioBox["![Embedded Audio Player](audio://content-onnlf)"]\)
```

Use Dirichlet window to perform no smoothing:

```wl
In[2]:=
AudioTimeStretch[a, 1.1, 
	PartitionGranularity -> {Quantity[46, "Milliseconds"], Quantity[10, "Milliseconds"], DirichletWindow}]

Out[2]= \!\(\*AudioBox["![Embedded Audio Player](audio://content-eoco9)"]\)
```

Specify a different window:

```wl
In[3]:=
AudioTimeStretch[a, 1.1, 
	PartitionGranularity -> {Quantity[46, "Milliseconds"], Quantity[10, "Milliseconds"], BlackmanWindow}]

Out[3]= \!\(\*AudioBox["![Embedded Audio Player](audio://content-eoco9)"]\)
```

### Applications (1)

Change the duration of an audio object to match the duration of another one:

```wl
In[1]:=
a1 = \!\(\*AudioBox["![Embedded Audio Player](audio://content-93ofj)"]\);
a2 = ExampleData[{"Audio", "Piano"}];

In[2]:= Duration /@ {a1, a2}

Out[2]= {Quantity[1.8, "Seconds"], Quantity[3.5560997732426305, "Seconds"]}
```

Stretch the audio to match the duration of the target one:

```wl
In[3]:= AudioTimeStretch[a1, Duration[a2]]

Out[3]= \!\(\*AudioBox["![Embedded Audio Player](audio://content-auccb)"]\)

In[4]:= Duration[%]

Out[4]= Quantity[3.5560997732426305, "Seconds"]
```

### Properties & Relations (1)

Change the duration of a recording by using a different sample rate:

```wl
In[1]:= a = \!\(\*AudioBox["![Embedded Audio Player](audio://content-ctqtq)"]\);
```

It will also affect the pitch:

```wl
In[2]:= Audio[a, SampleRate -> 11025]

Out[2]= \!\(\*AudioBox["![Embedded Audio Player](audio://content-wvdts)"]\)
```

``AudioTimeStretch`` does not alter the pitch:

```wl
In[3]:= AudioTimeStretch[a, 22050 / 11025]

Out[3]= \!\(\*AudioBox["![Embedded Audio Player](audio://content-4egay)"]\)
```

### Possible Issues (2)

The quality of the result degrades with large stretch parameters:

```wl
In[1]:= AudioTimeStretch[\!\(\*AudioBox["![Embedded Audio Player](audio://content-ctqtq)"]\), 5.6]

Out[1]= \!\(\*AudioBox["![Embedded Audio Player](audio://content-5q86e)"]\)
```

---

Using ``Method -> "Speech"`` for non-speech signals may not lead to expected results:

```wl
In[1]:=
a = \!\(\*AudioBox["![Embedded Audio Player](audio://content-g88rt)"]\);
AudioTimeStretch[a, 1.8, Method -> "Speech"]

Out[1]= \!\(\*AudioBox["![Embedded Audio Player](audio://content-22j9r)"]\)
```

## See Also

* [`AudioPitchShift`](https://reference.wolfram.com/language/ref/AudioPitchShift.en.md)
* [`AudioFrequencyShift`](https://reference.wolfram.com/language/ref/AudioFrequencyShift.en.md)
* [`AudioTrackApply`](https://reference.wolfram.com/language/ref/AudioTrackApply.en.md)
* [`VideoTimeStretch`](https://reference.wolfram.com/language/ref/VideoTimeStretch.en.md)
* [`AudioResample`](https://reference.wolfram.com/language/ref/AudioResample.en.md)
* [`Duration`](https://reference.wolfram.com/language/ref/Duration.en.md)

## Related Guides

* [Audio Editing](https://reference.wolfram.com/language/guide/AudioEditing.en.md)
* [Speech Computation](https://reference.wolfram.com/language/guide/SpeechComputation.en.md)
* [Video Computation: Update History](https://reference.wolfram.com/language/guide/VideoComputation-UpdateHistory.en.md)

## History

* [Introduced in 2016 (11.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn110.en.md) \| [Updated in 2020 (12.1)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn121.en.md) ▪ [2024 (14.1)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn141.en.md)