Qu

codec.write_wav

Builtin index · File I/O

codec.write_wav(path, x, depth=, [dither=])

Input: path, x, depth, dither · Output: no output

What it is

Writes audio out as a WAV file. path (string) is the destination, overwritten if it exists. x is a Signal, or a List of Signals for a multi-channel file — a signal carries its own sample rate, so there is no fs= argument to get wrong, and the rates of a list have to agree because a WAV header holds exactly one. depth (number, named, required) is 16, 24 or 32, where 32 means 32-bit float. dither (string, named) is "tpdf" or "none", and at depth=16 it is required — see below.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
codec.write_wav(path, x, depth=, [dither=])
path stringpath (string) is the destination, overwritten if it exists.
x Signal or Listx is a Signal, or a List of Signals for a multi-channel file — a signal carries its own sample rate, so there is no fs= argument to get wrong, and the rates of a list have to agree because a WAV header holds exactly one.
depth numberdepth (number, named, required) is 16, 24 or 32, where 32 means 32-bit float.
dither string, optionaldither (string, named) is "tpdf" or "none", and at depth=16 it is required — see below.
no outputWrites audio out as a WAV file.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

import codec

codec.write_wav("out.wav", x, depth = 16)
# error -- depth = 16 quantises 64-bit samples down to 16 bits, and doing

# that without saying how is an error: silent truncation of audio is

# audible. Name dither = "tpdf" or dither = "none".

not run by the build — this one needs something the repository cannot supply · from file-io

import codec

a = codec.decode_wav("take.wav")            # a stereo file

codec.write_wav("take24.wav", a.channels, depth = 24)
codec.write_wav("take16.wav", a.channels, depth = 16, dither = "tpdf")

not run by the build — this one needs something the repository cannot supply · from file-io