sndwrite_like
- sndfileio.sndwrite_like(outfile, samples, likefile, sr=None, metadata=None)[source]
Write samples to outfile with samplerate/fileformat/encoding taken from likefile
- Parameters:
outfile (
str
) – the file to write tosamples (
ndarray
) – the samples to writelikefile (
str
) – the file to use as a reference for sr, format and encodingsr (
Optional
[int
]) – sample rate can be overriddenmetadata (
Optional
[dict
[str
,str
]]) – a dict {str: str}, overrides metadata in likefile. Metadata is not merged, so if metadata is given, it substitutes the metadata in likefile completely. In order to merge it, do that beforehand If None is passed, the metadata in likefile is written to outfile
- Return type:
None
Note
The fileformat is always determined by likefile, even if the extension of outfile would result in a different format. For example, if likefile has a flac format but outfile has a .wav extension, the resulting file will be written in flac format.
Example
# Read a file, apply a fade-in of 0.5 seconds, save it import numpy as np from sndfileio import * samples, sr = sndread("stereo.wav") fadesize = int(0.5*sr) ramp = np.linspace(0, 1, fadesize)) samples[:fadesize, 0] *= ramp samples[:fadesize, 1] *= ramp sndwrite_like(samples, "stereo.wav", "out.wav")