save_waveform#

scikitplot.doremi.save_waveform(waveform, file_path='output.wav', ext=None, sample_rate=44100, backend=None, dtype='float32', normalize=True, stereo_out=True, **kwargs)[source]#

Save waveform to an audio file using specified or auto-selected backend.

Parameters:
waveformnp.ndarray | array-like

Audio array, 1D or 2D. Will be reshaped, normalized, and cast.

file_pathstr, default=”output.wav”

Output file_path.

extstr or None, optional

File extension override (e.g., ‘wav’, ‘flac’). Inferred from file_path if None.

sample_rateint, default=44100

Sample rate in Hz. Defaults to 44100 if None.

backendstr or None, optional

Audio backend to use: ‘scipy’, ‘soundfile’, or ‘scitools’. Auto-selected based on extension if None.

dtypestr, default=’int16’

Output audio dtype: ‘int16’ or ‘float32’.

normalizebool, default=True

Whether to normalize waveform amplitude to [-1,1].

stereo_outbool

Convert mono to stereo by duplication if True.

**kwargs

Additional arguments passed to backend writers.

Returns:
str

The file path of the saved audio.

Raises:
ValueError

If backend unsupported or invalid extension for backend.

Parameters:
Return type:

str

Notes

  • 1D mono and 2D multi-channel supported.

  • Channel dimension must be second in shape (samples, channels).

  • Audio will be passed through preprocess_audio before saving.

  • Mono audio should be saved as a 1D array with shape (samples,).

  • Audio file formats like WAV expect mono data as a single stream of samples, 1D array.

  • Most audio libraries (e.g., soundfile, scipy.io.wavfile, librosa.output.write_wav) accept mono data as 1D arrays.

  • Stereo/multi-channel audio must be saved as a 2D array with shape (samples, channels).

  • The order of dimensions is important, channels must be the second dimension for correct playback.

  • Saving with the wrong shape (e.g., (channels, samples)) will cause audio distortion or channel mix-up.

Examples

>>> import numpy as np
>>> tone = 0.5 * np.sin(2 * np.pi * 440 * np.linspace(0, 1, 44100))
>>> save_waveform(tone, "tone.wav", dtype="int16")