Table of Contents

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

T

The 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

minShiftFraction double

Minimum shift fraction (default: -0.2).

maxShiftFraction double

Maximum shift fraction (default: 0.2).

probability double

Probability of applying this augmentation (default: 0.5).

sampleRate int

Sample 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

double

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

double

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

bool

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

data Tensor<T>

The input data.

context AugmentationContext<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.