PitchShift
- class audioflux.PitchShift(radix2_exp=12, slide_length=1024, window_type=WindowType.HANN)
Pitch shift algorithm
- Parameters
- radix2_exp: int
fft_length=2**radix2_exp
- slide_length: int
Window sliding length.
- window_type: WindowType
Window type for each frame.
See:
type.WindowType
Examples
Read voice audio data
>>> import audioflux as af >>> audio_path = af.utils.sample_path('voice') >>> audio_arr, sr = af.read(audio_path)
Compute pitch shift
>>> pitch_shift_obj = af.PitchShift(radix2_exp=12, slide_length=1024, window_type=af.type.WindowType.HANN) >>> audio_arr1 = pitch_shift_obj.pitch_shift(audio_arr, n_semitone=6, samplate=sr) >>> # af.write('./audio_arr1.wav', audio_arr1, sr)
Show plot
>>> yin_obj = af.PitchYIN(samplate=sr) >>> pitch_arr, _, _ = yin_obj.pitch(audio_arr) >>> pitch_arr1, _, _ = yin_obj.pitch(audio_arr1)
>>> import matplotlib.pyplot as plt >>> fig, ax = plt.subplots() >>> times = np.arange(len(pitch_arr)) * (yin_obj.slide_length / sr) >>> ax.scatter(times, pitch_arr, s=2, label='Original') >>> ax.scatter(times, pitch_arr1, s=2, label='Pitch Shift') >>> ax.set_ylim(200, 750) >>> ax.legend()
Methods
pitch_shift
(data_arr, n_semitone[, samplate])Compute the time stretch
- pitch_shift(data_arr, n_semitone, samplate=32000)
Compute the time stretch
- Parameters
- data_arr: np.ndarray [shape=(…, n)]
Audio data array
- n_semitone: int
Pitch shift in semitone. -12 <= n_semitone <= 12.
- samplate: int
Sample rate
- Returns
- arr: np.ndarray [shape=(…, n)]