Soundfile¶
Functions to inspect or write an audio file on disk.
Functions in this category¶
- sndinfo(): Retrieve informations about a soundfile.
- savefile(): Creates an audio file from a list of floats.
- savefileFromTable(): Creates an audio file from the content of a table.
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. 
- raise_on_failure: boolean, optional
- If True, sndinfo will raise an exception when failing to get file info. Defaults to False. 
 
 - >>> path = SNDS_PATH + '/transparent.aif' >>> print(path) /home/olivier/.local/lib/python3.9/site-packages/pyo/lib/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: - WAVE - Microsoft WAV format (little endian) {.wav, .wave} 
- AIFF - Apple/SGI AIFF format (big endian) {.aif, .aiff} 
- AU - Sun/NeXT AU format (big endian) {.au} 
- RAW - RAW PCM data {no extension} 
- SD2 - Sound Designer 2 {.sd2} 
- FLAC - FLAC lossless file format {.flac} 
- CAF - Core Audio File format {.caf} 
- 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: - 16 bit int 
- 24 bit int 
- 32 bit int 
- 32 bit float 
- 64 bit float 
- U-Law encoded 
- 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: - WAVE - Microsoft WAV format (little endian) {.wav, .wave} 
- AIFF - Apple/SGI AIFF format (big endian) {.aif, .aiff} 
- AU - Sun/NeXT AU format (big endian) {.au} 
- RAW - RAW PCM data {no extension} 
- SD2 - Sound Designer 2 {.sd2} 
- FLAC - FLAC lossless file format {.flac} 
- CAF - Core Audio File format {.caf} 
- 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: - 16 bit int 
- 24 bit int 
- 32 bit int 
- 32 bit float 
- 64 bit float 
- U-Law encoded 
- 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)