[ SciPy v1.12.0 Manual  ](../../index.html)

  * [ Installing ](https://scipy.org/install/)
  * [ User Guide ](../../tutorial/index.html)
  * [ API reference ](../index.html)
  * [ Building from source ](../../building/index.html)
  * [ Development ](../../dev/index.html)
  * [ Release notes ](../../release.html)

__ __ __

1.12.0

  * [ __ GitHub  ](https://github.com/scipy/scipy "GitHub")
  * [ __ Twitter  ](https://twitter.com/SciPy_team "Twitter")

__

  * [ scipy ](../main_namespace.html)
  * [ scipy.cluster ](../cluster.html)
  * [ scipy.constants ](../constants.html)
  * [ scipy.datasets ](../datasets.html)
  * [ scipy.fft ](../fft.html)
  * [ scipy.fftpack ](../fftpack.html)
  * [ scipy.integrate ](../integrate.html)
  * [ scipy.interpolate ](../interpolate.html)
  * [ scipy.io ](../io.html)
  * [ scipy.linalg ](../linalg.html)
  * [ scipy.misc ](../misc.html)
  * [ scipy.ndimage ](../ndimage.html)
  * [ scipy.odr ](../odr.html)
  * [ scipy.optimize ](../optimize.html)
  * [ scipy.signal ](../signal.html)
  * [ scipy.sparse ](../sparse.html)
  * [ scipy.spatial ](../spatial.html)
  * [ scipy.special ](../special.html)
  * [ scipy.stats ](../stats.html)

__ On this page

  * ` write  `

#  scipy.io.wavfile.write  #

scipy.io.wavfile.  write  (  _ filename  _ , _ rate  _ , _ data  _ )  [
[source]
](https://github.com/scipy/scipy/blob/v1.12.0/scipy/io/wavfile.py#L709-L834) #

    

Write a NumPy array as a WAV file.

Parameters  :

    

**filename** string or open file handle

    

Output wav file.

**rate** int

    

The sample rate (in samples/sec).

**data** ndarray

    

A 1-D or 2-D NumPy array of either integer or float data-type.

Notes

  * Writes a simple uncompressed WAV file. 

  * To write multiple-channels, use a 2-D array of shape (Nsamples, Nchannels). 

  * The bits-per-sample and PCM/float will be determined by the data-type. 

Common data types:  [1]

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   
  
Note that 8-bit PCM is unsigned.

References

[  1  ]

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
](http://www.tactilemedia.com/info/MCI_Control_Info.html)

Examples

Create a 100Hz sine wave, sampled at 44100Hz. Write to 16-bit PCM, Mono.

    
    
    >>> from scipy.io.wavfile import write
    >>> import numpy as np
    >>> samplerate = 44100; fs = 100
    >>> t = np.linspace(0., 1., samplerate)
    >>> amplitude = np.iinfo(np.int16).max
    >>> data = amplitude * np.sin(2. * np.pi * fs * t)
    >>> write("example.wav", samplerate, data.astype(np.int16))
    

[ __ previous  scipy.io.wavfile.read  ](scipy.io.wavfile.read.html "previous
page") [ next  scipy.io.wavfile.WavFileWarning  __
](scipy.io.wavfile.WavFileWarning.html "next page")

© Copyright 2008-2024, The SciPy community.  

Created using [ Sphinx ](http://sphinx-doc.org/) 7.2.6.