Note
Go to the end to download the full example code.
Time stretch and pitch shift
time_stretch changes the length and keeps the pitch; pitch_shift changes
the pitch and keeps the length.
import numpy as np
import audio_samples as aus
from audio_samples import mpl
sr = 22050
audio = aus.generation.compound_tone([(220.0, 0.6), (440.0, 0.3), (660.0, 0.1)], 2.0, sr).as_f32()
audio
rate=1.5 plays 1.5 times as fast, so the result is two thirds as long.
Twelve semitones up is one octave: 220 Hz becomes 440 Hz.
440.1 Hz

Total running time of the script: (0 minutes 0.448 seconds)