maad.sound.write
- maad.sound.write(filename, fs, data, bit_depth=None)[source]
Write a NumPy array as a WAV file with the Scipy method. [1]
- Parameters:
- filenamestring or open file handle
Name of output wav file.
- fsint
Sample rate (samples/sec).
- datandarray
Mono or stereo signal as NumPy array.
- bit_depth: int
Specifies the bit depth format of the audio recording. Should be one of 8, 16 or 32. If None, bit depth will be determined from the Numpy data type. See section Common data types.
See also
scipy.io.wavfile.write
Notes
The data-type determines the bits-per-sample and PCM/float.
Common data types: [2]
WAV format
Min
Max
NumPy dtype
32-bit floating-point
-1.0
+1.0
float32
32-bit PCM
-2147483648
+2147483647
int32
16-bit PCM
-32768
+32767
int16
8-bit PCM
0
255
uint8
References
[1]The SciPy community, “scipy.io.wavfile.write”, v1.6.0. https://docs.scipy.org/doc/scipy/reference/generated/scipy.io.wavfile.write.html
[2]IBM Corporation and Microsoft Corporation, “Multimedia Programming Interface and Data Specifications 1.0”, section “Data Format of the Samples”, August 1991 http://www.tactilemedia.com/info/MCI_Control_Info.html
Examples
>>> from maad import sound
Synthesize a 440Hz sine wave at 44100 Hz and write it to disk.
>>> import numpy as np >>> fs = 44100; T = 2.0 >>> t = np.linspace(0, T, int(T*fs)) >>> data = np.sin(2. * np.pi * 440. *t) >>> sound.write('example.wav', fs, data, bit_depth=16)
Open an audio file, filter a frequency band and write to disk specifying the bit depth.
>>> s, fs = sound.load('../data/spinetail.wav') >>> s_filt = sound.sinc(s, (3000, 10000), fs) >>> sound.write('spinetail_filtered.wav', fs, s_filt, bit_depth=16)