SndWriter

class sndfileio.SndWriter(sr, outfile, encoding, fileformat=None, bitrate=0, backend=None, metadata=None)[source]

Bases: object

Class returned by sndwrite_chunked() to write samples

Parameters:
  • backend – the Backend instance which created this SndWriter

  • sr (int) – the samplerate

  • outfile (str) – the file to wite

  • encoding (str) – the encoding of the file (pcmXX, floatXX, where XX represents the bits per sample)

  • fileformat (Optional[str]) – the fileformat, only needed if the format indicated by the extension in outfile should be overridden

  • metadata (Optional[dict[str, str]]) – a dict {str: str}.

Metadata Possible Keys:

  • title

  • comment

  • artist

  • album

  • tracknumber

  • software

Example

>>> from sndfileio import *
>>> writer = sndwrite_chunked("out.flac", 44100)
# writer is a SndWriter
>>> for buf in sndread_chunked("in.flac"):
...     # do some processing, like changing the gain
...     buf *= 0.5
...     writer.write(buf)

Attributes Summary

filetypes

Methods Summary

__call__(frames)

Write the given sample data.

close()

Explicitely close this file

write(frames)

Write the given sample data.

Attributes Documentation

filetypes

Methods Documentation

__call__(frames)[source]

Write the given sample data.

The first array will determine the number of channels to write

Parameters:

frames (np.ndarray) – the samples to write

Return type:

None

close()[source]

Explicitely close this file

Return type:

None

write(frames)[source]

Write the given sample data.

The first array will determine the number of channels to write

Parameters:

frames (np.ndarray) – the samples to write

Return type:

None