pyfar.io

Functions:

read(filename)

Read any compatible pyfar object or numpy array (.far file) from disk.

read_sofa(filename)

Import a SOFA file as Signal object.

read_wav(filename)

Import a WAV file as Signal object.

write(filename[, compress])

Write any compatible pyfar object or numpy array as .far file to disk.

write_wav(signal, filename[, overwrite])

Write a Signal object as a WAV file to disk.

pyfar.io.read(filename)[source]

Read any compatible pyfar object or numpy array (.far file) from disk.

Parameters

filename (string, Path) – Input file. If no extension is provided, .far-suffix is added.

Returns

collection – Contains pyfar objects like { 'name1': 'obj1', 'name2': 'obj2' ... }.

Return type

dict

Examples

Read signal and orientations objects stored in a .far file.

>>> collection = pyfar.read('my_objs.far')
>>> my_signal = collection['my_signal']
>>> my_orientations = collection['my_orientations']
pyfar.io.read_sofa(filename)[source]

Import a SOFA file as Signal object.

Parameters

filename (string, Path) – Input SOFA file (cf. 1, 2).

Returns

  • signal (Signal) – Signal object containing the data stored in SOFA_Object.Data.IR. cshape is equal to (number of measurements, number of receivers).

  • source_coordinates (Coordinates) – Coordinates object containing the data stored in SOFA_object.SourcePosition. The domain, convention and unit are automatically matched.

  • receiver_coordinates (Coordinates) – Coordinates object containing the data stored in SOFA_object.RecevierPosition. The domain, convention and unit are automatically matched.

Notes

  • This function is based on the python-sofa 3.

  • Currently, only SOFA files of DataType FIR are supported.

References

1

https://www.sofaconventions.org

2

“AES69-2015: AES Standard for File Exchange-Spatial Acoustic Data File Format.”, 2015.

3

https://github.com/spatialaudio/python-sofa

pyfar.io.read_wav(filename)[source]

Import a WAV file as Signal object.

Parameters

filename (string, Path) – Input file.

Returns

signalSignal object containing the audio data from the WAV file.

Return type

Signal

Notes

  • This function is based on scipy.io.wavfile.read.

  • 24-bit data cannot be read.

pyfar.io.write(filename, compress=False, **objs)[source]

Write any compatible pyfar object or numpy array as .far file to disk.

Parameters
  • filename (string) – Full path or filename. If now extension is provided, .far-suffix will be add to filename.

  • compress (bool) – Default is False (uncompressed). Compressed files take less disk space but need more time for writing and reading.

  • **objs – Objects to be saved as key-value arguments, e.g., name1=object1, name2=object2.

Examples

Save Signal object, Orientations objects and numpy array to disk.

>>> s = pyfar.Signal([1, 2, 3], 44100)
>>> o = pyfar.Orientations.from_view_up([1, 0, 0], [0, 1, 0])
>>> a = np.array([1,2,3])
>>> pyfar.io.write('my_objs.far', signal=s, orientations=o, array=a)
pyfar.io.write_wav(signal, filename, overwrite=True)[source]

Write a Signal object as a WAV file to disk.

Parameters
  • signal (Signal) – Object to be written.

  • filename (string, Path) – Output file.

  • overwrite (bool) – Select wether to overwrite the WAV file, if it already exists. The default is True.

Notes

  • Signals are flattened before writing to disk (e.g. a signal with cshape = (3, 2) will be written to disk as a six channel wav file).

  • This function is based on scipy.io.wavfile.write.

  • The bits-per-sample and PCM/float is determined by the data-type, see documentation for scipy.io.wavfile.write.