Class PitchShift<T>
- Namespace
- AiDotNet.Augmentation.Audio
- Assembly
- AiDotNet.dll
Shifts the pitch of audio without changing tempo using WSOLA (Waveform Similarity Overlap-Add).
public class PitchShift<T> : AudioAugmenterBase<T>, IAugmentation<T, Tensor<T>>
Type Parameters
TThe numeric type for calculations.
- Inheritance
-
AugmentationBase<T, Tensor<T>>PitchShift<T>
- Implements
-
IAugmentation<T, Tensor<T>>
- Inherited Members
Remarks
For Beginners: Pitch shifting makes audio sound higher or lower, like the difference between a high and low voice, while keeping the same duration.
Algorithm: Uses WSOLA (Waveform Similarity Overlap-Add) for time-stretching followed by resampling. This preserves audio quality better than simple resampling.
When to use:
- Speech recognition to handle different voice pitches
- Music analysis to handle different keys
- Voice cloning and synthesis training
Semitone reference: 12 semitones = 1 octave (doubling/halving frequency)
Constructors
PitchShift(double, double, double, int)
Creates a new pitch shift augmentation.
public PitchShift(double minSemitones = -2, double maxSemitones = 2, double probability = 0.5, int sampleRate = 16000)
Parameters
minSemitonesdoubleMinimum pitch shift in semitones (default: -2.0).
maxSemitonesdoubleMaximum pitch shift in semitones (default: 2.0).
probabilitydoubleProbability of applying this augmentation (default: 0.5).
sampleRateintSample rate of the audio in Hz (default: 16000).
Properties
MaxSemitones
Gets the maximum pitch shift in semitones.
public double MaxSemitones { get; }
Property Value
Remarks
Default: 2.0 semitones (about +12% frequency)
Positive values raise the pitch.
MinSemitones
Gets the minimum pitch shift in semitones.
public double MinSemitones { get; }
Property Value
Remarks
Default: -2.0 semitones (about -12% frequency)
Negative values lower the pitch.
Methods
ApplyAugmentation(Tensor<T>, AugmentationContext<T>)
Implement this method to perform the actual augmentation.
protected override Tensor<T> ApplyAugmentation(Tensor<T> data, AugmentationContext<T> context)
Parameters
dataTensor<T>The input data.
contextAugmentationContext<T>The augmentation context.
Returns
- Tensor<T>
The augmented data.
GetParameters()
Gets the parameters of this augmentation.
public override IDictionary<string, object> GetParameters()
Returns
- IDictionary<string, object>
A dictionary of parameter names to values.