def _writer_factory(name, format, def_fs, descr):
    """ Create a writer function with fileformat described by format, default
    sampling rate def_fs, and docstring descr."""
    def basic_writer(data, filename, fs = def_fs, enc = format.encoding):
        """Common "template" to all write functions."""
        if np.ndim(data) <= 1:
            nc      = 1
        elif np.ndim(data) == 2:
            nc      = data.shape[1]
        else:
            RuntimeError("Only rank 0, 1, and 2 arrays supported as audio data")

        uformat = Format(format.file_format, encoding=enc,
                             endianness=format.endianness)
        hdl = Sndfile(filename, 'w', uformat, nc, fs)
        try:
            hdl.write_frames(data)
        finally:
            hdl.close()
    doc = \
    """Simple writer for %(format)s audio files.

    Parameters
    ----------
    data : array
        a rank 1 (mono) or 2 (one channel per col) numpy array
    filename : str
        audio file name
    fs : scalar
        sampling rate in Hz (%(def_fs)s by default)
    enc : str
        The encoding such as 'pcm16', etc...(%(def_enc)s by default). A
        list of supported encodings can be queried through the function
        available_encodings.

    Notes
    -----
    OVERWRITES EXISTING FILE !

    These functions are similar to matlab's wavwrite/auwrite and the
    like.  For total control over options, such as endianness, appending data
    to an existing file, etc...  you should use Sndfile class instances
    instead

    See also
    --------
    available_encodings, Sndfile, Format""" \
            % {'format' : str(descr), 'def_fs': def_fs,
               'def_enc': format.encoding}
    basic_writer.__doc__    = doc
    basic_writer.__name__   = name
    return basic_writer
def _writer_factory ( name , format , def_fs , descr ) : def basic_writer ( data , filename , fs = def_fs , enc = format . encoding ) : if np . ndim ( data ) <= 1 : nc = 1 elif np . ndim ( data ) == 2 : nc = data . shape [ 1 ] else : RuntimeError ( "Only rank 0, 1, and 2 arrays supported as audio data" ) uformat = Format ( format . file_format , encoding = enc , endianness = format . endianness ) hdl = Sndfile ( filename , 'w' , uformat , nc , fs ) try : hdl . write_frames ( data ) finally : hdl . close ( ) doc = """Simple writer for %(format)s audio files.
    Parameters
    ----------
    data : array
        a rank 1 (mono) or 2 (one channel per col) numpy array
    filename : str
        audio file name
    fs : scalar
        sampling rate in Hz (%(def_fs)s by default)
    enc : str
        The encoding such as 'pcm16', etc...(%(def_enc)s by default). A
        list of supported encodings can be queried through the function
        available_encodings.
    Notes
    -----
    OVERWRITES EXISTING FILE !
    These functions are similar to matlab's wavwrite/auwrite and the
    like.  For total control over options, such as endianness, appending data
    to an existing file, etc...  you should use Sndfile class instances
    instead
    See also
    --------
    available_encodings, Sndfile, Format""" % { 'format' : str ( descr ) , 'def_fs' : def_fs , 'def_enc' : format . encoding } basic_writer . __doc__ = doc basic_writer . __name__ = name return basic_writer
Create a writer function with fileformat described by format, default
    sampling rate def_fs, and docstring descr.