Class WaveFile
Represents a WAV audio file, exposing its channels, sample rate, bit depth, and duration, and providing methods to read normalized audio samples.
public sealed class WaveFile : IDisposable
- Inheritance
-
WaveFile
- Implements
- Inherited Members
Constructors
- WaveFile(IList<float>, uint)
Creates a new WaveFile instance from normalized mono float samples.
- WaveFile(Stream, bool)
Initializes a new WaveFile from the provided
stream
.
- WaveFile(Memory<byte>)
Initializes a new WaveFile by reading WAV data from the given in-memory buffer.
- WaveFile(string)
Initializes a new WaveFile by opening the WAV file at the specified
path
, reading its audio header information and locating the data section.
Properties
- BitsPerSample
Gets the bit depth per sample in the WAV stream.
- Channels
Gets the number of audio channels in the WAV stream.
- Duration
Gets the total duration of the audio in the WAV stream.
- EnableLowPassFilter
Gets or sets whether to apply a Hamming-windowed sinc FIR low-pass filter before resampling to 16 kHz. Defaults to true (filter enabled). When enabled, reduces aliasing and smooths audio at the cost of extra CPU usage and processing time.
- SampleRate
Gets the sample rate, in hertz, of the WAV stream.
Methods
- GetChannel16kSamples(int, CancellationToken)
Reads and returns normalized samples for a single channel, and resamples to 16 kHz if necessary.
- GetMono16kSamples(CancellationToken)
Reads and returns the per-frame average across all channels, normalized into [-1, 1], and resampled to 16 kHz if necessary.
- IsValidWaveFile(Stream)
Determines whether the WAV data in the specified stream is valid.
- IsValidWaveFile(Memory<byte>)
Determines whether the specified in-memory buffer contains a valid WAV file.
- IsValidWaveFile(string)
Determines whether the WAV file at the specified path is valid.
- LowPassFilter(float[], int, float, int)
Applies a Hamming-windowed sinc FIR low-pass filter to the input data.
- SaveAsMono16k(Stream, CancellationToken)
Saves the current WAV as a 16 kHz, mono, 16-bit PCM WAV file to the given stream. The stream is left open after writing.
- SaveAsMono16k(string, CancellationToken)
Saves the current WAV as a 16 kHz, mono, 16-bit PCM WAV file to the given path.