code: def write(filename, rate, data):
      """
      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
  
      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))
  
      """
      if hasattr(filename, "write"):
          fid = filename
      else:
          fid = open(filename, "wb")
  
      fs = rate
  
      try:
          dkind = data.dtype.kind
          if not (
              dkind == "i"
              or dkind == "f"
              or (dkind == "u" and data.dtype.itemsize == 1)
          ):
              raise ValueError(
                  "Unsupported data type '%s'" % data.dtype
              )
  
          header_data = b""
  
          header_data += b"RIFF"
          header_data += b"\x00\x00\x00\x00"
          header_data += b"WAVE"
  
          # fmt chunk
          header_data += b"fmt "
          if dkind == "f":
              format_tag = WAVE_FORMAT.IEEE_FLOAT
          else:
              format_tag = WAVE_FORMAT.PCM
          if data.ndim == 1:
              channels = 1
          else:
              channels = data.shape[1]
          bit_depth = data.dtype.itemsize * 8
          bytes_per_second = fs * (bit_depth // 8) * channels
          block_align = channels * (bit_depth // 8)
  
          fmt_chunk_data = struct.pack(
              "<HHIIHH",
              format_tag,
              channels,
              fs,
              bytes_per_second,
              block_align,
              bit_depth,
          )
          if not (dkind == "i" or dkind == "u"):
              # add cbSize field for non-PCM files
              fmt_chunk_data += b"\x00\x00"
  
          header_data += struct.pack("<I", len(fmt_chunk_data))
          header_data += fmt_chunk_data
  
          # fact chunk (non-PCM files)
          if not (dkind == "i" or dkind == "u"):
              header_data += b"fact"
              header_data += struct.pack("<II", 4, data.shape[0])
  
          # check data size (needs to be immediately before the data chunk)
          if (
              (len(header_data) - 4 - 4) + (4 + 4 + data.nbytes)
          ) > 0xFFFFFFFF:
              raise ValueError("Data exceeds wave file size limit")
  
          fid.write(header_data)
  
          # data chunk
          fid.write(b"data")
          fid.write(struct.pack("<I", data.nbytes))
          if data.dtype.byteorder == ">" or (
              data.dtype.byteorder == "=" and sys.byteorder == "big"
          ):
              data = data.byteswap()
          _array_tofile(fid, data)
  
          # Determine file size and place it in correct
          #  position at start of the file.
          size = fid.tell()
          fid.seek(4)
          fid.write(struct.pack("<I", size - 8))
  
      finally:
          if not hasattr(filename, "write"):
              fid.close()
          else:
              fid.seek(0)
  
file_path: scipy/scipy/io/wavfile.py
imports: import io
  import sys
  import numpy
  import struct
  import warnings
  from enum import IntEnum
label_desc: Use image node_id 8 for calling a global function with example usage: write(filename, rate, data) without return types