Class TimeShift<T>
- Namespace
- AiDotNet.Augmentation.Audio
- Assembly
- AiDotNet.dll
Shifts audio forward or backward in time.
public class TimeShift<T> : AudioAugmenterBase<T>, IAugmentation<T, Tensor<T>>
Type Parameters
TThe numeric type for calculations.
- Inheritance
-
AugmentationBase<T, Tensor<T>>TimeShift<T>
- Implements
-
IAugmentation<T, Tensor<T>>
- Inherited Members
Remarks
For Beginners: Time shifting moves audio forward or backward, like adding silence at the beginning or end. This simulates different recording start times and helps models handle timing variations.
Handling shifted samples:
- Wrap: Samples that go off one end appear at the other (circular)
- Zero: Shifted areas are filled with silence
Constructors
TimeShift(double, double, double, int)
Creates a new time shift augmentation.
public TimeShift(double minShiftFraction = -0.2, double maxShiftFraction = 0.2, double probability = 0.5, int sampleRate = 16000)
Parameters
minShiftFractiondoubleMinimum shift fraction (default: -0.2).
maxShiftFractiondoubleMaximum shift fraction (default: 0.2).
probabilitydoubleProbability of applying this augmentation (default: 0.5).
sampleRateintSample rate of the audio in Hz (default: 16000).
Properties
MaxShiftFraction
Gets the maximum shift as a fraction of total duration.
public double MaxShiftFraction { get; }
Property Value
Remarks
Default: 0.2 (20% forward)
Positive values shift audio forward in time (content moves later, silence fills start).
MinShiftFraction
Gets the minimum shift as a fraction of total duration.
public double MinShiftFraction { get; }
Property Value
Remarks
Default: -0.2 (20% backward)
Negative values shift audio backward in time (content moves earlier, silence fills end).
WrapAround
Gets or sets whether to wrap shifted samples (true) or fill with zeros (false).
public bool WrapAround { get; set; }
Property Value
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.