WriteWAV#

class acoular.tprocess.WriteWAV

Bases: TimeOut

Saves time signal from one or more channels as mono, stereo, or multi-channel .wav file.

Inherits from TimeOut and allows for exporting time-series data from one or more channels to a WAV file. Supports saving mono, stereo, or multi-channel signals to disk with automatic or user-defined file naming.

See also

TimeOut

ABC for signal processing blocks that interact with data from a source.

SamplesGenerator

Interface for generating multi-channel time domain signal processing blocks.

wave

Python module for handling WAV files.

source = Instance(SamplesGenerator)

The input data source. It must be an instance of a SamplesGenerator-derived class.

file = File(filter=['*.wav'])

The name of the file to be saved. If none is given, the name will be automatically generated from the source.

basename = Property(depends_on=['digest'])

The name of the cache file (without extension). It serves as an internal reference for data caching and tracking processed files. (automatically generated)

channels = List(int)

The list of channels to save. Can only contain one or two channels.

encoding = Enum('uint8', 'int16', 'int32')

bit depth of the output file

max_val = Either(None, Float)

Maximum value to scale the output to.

digest = Property(depends_on=['source.digest', 'channels'])

A unique identifier for the filter, based on its properties. (read-only)

result(num)

Generate and save time signal data as a WAV file in blocks.

This generator method retrieves time signal data from the source and writes it to a WAV file in blocks of size num. The data is scaled and encoded according to the selected bit depth and channel configuration. If no file name is specified, a name is generated automatically. The method yields each block of data after it is written to the file, allowing for streaming or real-time processing.

Parameters:
numint

Number of samples per block to write and yield.

Yields:
numpy.ndarray

The block of time signal data that was written to the WAV file, with shape (num, number of channels).

Raises:
ValueError

If no channels are specified for output.

Warning

If more than two channels are specified, or if the sample frequency is not an integer. Also warns if clipping occurs due to data range limitations.

See also

save()

Save the entire source output to a WAV file in one call.

save()

Save the entire source output to a WAV file.

This method writes all available time signal data from the source to the specified WAV file in blocks. It calls the result() method internally and discards the yielded data. The file is written according to the current channels, encoding, and scaling settings. If no file name is specified, a name is generated automatically.

See also

result()

Generator for writing and yielding data block-wise.