Soundfile

sndinfo

sndinfo(path, print=False)[source]

Retrieve informations about a soundfile.

Prints the infos of the given soundfile to the console and returns a tuple containing:

(number of frames, duration in seconds, sampling rate,
number of channels, file format, sample type)
Args:
path: string

Path of a valid soundfile.

print: boolean, optional

If True, sndinfo will print sound infos to the console. Defaults to False.

>>> path = SNDS_PATH + '/transparent.aif'
>>> print(path)
/usr/lib/python2.7/dist-packages/pyolib/snds/transparent.aif
>>> info = sndinfo(path)
>>> print(info)
(29877, 0.6774829931972789, 44100.0, 1, 'AIFF', '16 bit int')

savefile

savefile(samples, path, sr=44100, channels=1, fileformat=0, sampletype=0, quality=0.4)[source]

Creates an audio file from a list of floats.

Args:
samples: list of floats

List of samples data, or list of list of samples data if more than 1 channels.

path: string

Full path (including extension) of the new file.

sr: int, optional

Sampling rate of the new file. Defaults to 44100.

channels: int, optional

Number of channels of the new file. Defaults to 1.

fileformat: int, optional
Format type of the new file. Defaults to 0. Supported formats are:
  1. WAVE - Microsoft WAV format (little endian) {.wav, .wave}
  2. AIFF - Apple/SGI AIFF format (big endian) {.aif, .aiff}
  3. AU - Sun/NeXT AU format (big endian) {.au}
  4. RAW - RAW PCM data {no extension}
  5. SD2 - Sound Designer 2 {.sd2}
  6. FLAC - FLAC lossless file format {.flac}
  7. CAF - Core Audio File format {.caf}
  8. OGG - Xiph OGG container {.ogg}
sampletype ; int, optional

Bit depth encoding of the audio file. Defaults to 0. SD2 and FLAC only support 16 or 24 bit int. Supported types are:

  1. 16 bit int
  2. 24 bit int
  3. 32 bit int
  4. 32 bit float
  5. 64 bit float
  6. U-Law encoded
  7. A-Law encoded
quality: float, optional

The encoding quality value, between 0.0 (lowest quality) and 1.0 (highest quality). This argument has an effect only with FLAC and OGG compressed formats. Defaults to 0.4.

>>> from random import uniform
>>> import os
>>> home = os.path.expanduser('~')
>>> sr, dur, chnls, path = 44100, 5, 2, os.path.join(home, 'noise.aif')
>>> samples = [[uniform(-0.5,0.5) for i in range(sr*dur)] for i in range(chnls)]
>>> savefile(samples=samples, path=path, sr=sr, channels=chnls, fileformat=1, sampletype=1)

savefileFromTable

savefileFromTable(table, path, fileformat=0, sampletype=0, quality=0.4)[source]

Creates an audio file from the content of a table.

Args:
table: PyoTableObject

Table from which to retrieve the samples to write.

path: string

Full path (including extension) of the new file.

fileformat: int, optional
Format type of the new file. Defaults to 0. Supported formats are:
  1. WAVE - Microsoft WAV format (little endian) {.wav, .wave}
  2. AIFF - Apple/SGI AIFF format (big endian) {.aif, .aiff}
  3. AU - Sun/NeXT AU format (big endian) {.au}
  4. RAW - RAW PCM data {no extension}
  5. SD2 - Sound Designer 2 {.sd2}
  6. FLAC - FLAC lossless file format {.flac}
  7. CAF - Core Audio File format {.caf}
  8. OGG - Xiph OGG container {.ogg}
sampletype ; int, optional

Bit depth encoding of the audio file. Defaults to 0. SD2 and FLAC only support 16 or 24 bit int. Supported types are:

  1. 16 bit int
  2. 24 bit int
  3. 32 bit int
  4. 32 bit float
  5. 64 bit float
  6. U-Law encoded
  7. A-Law encoded
quality: float, optional

The encoding quality value, between 0.0 (lowest quality) and 1.0 (highest quality). This argument has an effect only with FLAC and OGG compressed formats. Defaults to 0.4.

>>> import os
>>> home = os.path.expanduser('~')
>>> path1 = SNDS_PATH + '/transparent.aif'
>>> path2 = os.path.join(home, '/transparent2.aif')
>>> t = SndTable(path1)
>>> savefileFromTable(table=t, path=path, fileformat=1, sampletype=1)