File: 01-list-to-audio-file.py

package info (click to toggle)
python-pyo 1.0.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,332 kB
  • sloc: python: 135,133; ansic: 127,822; javascript: 16,116; sh: 395; makefile: 388; cpp: 242
file content (28 lines) | stat: -rw-r--r-- 811 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""
Saving list of floats to audio file on disk

**01-list-to-audio-file.py**

This program generates 5 seconds of white noise with pure python function
and saves the samples in a file called noise.aif on the Desktop.

"""

from pyo import savefile
from random import uniform
import os

# Create the path for the audio file.
home = os.path.expanduser("~")
path = os.path.join(home, "Desktop", "noise.aif")

# Audio file properties (sampling rate, duration and number of channels).
sr = 44100
dur = 5
chnls = 2

# Generate a list of `chnls` sub-lists with `sr * dur` floats in each of them.
samples = [[uniform(-0.5, 0.5) for i in range(sr * dur)] for i in range(chnls)]

# Save the list of floats in an audio file on disk.
savefile(samples=samples, path=path, sr=sr, channels=chnls, fileformat=1, sampletype=1)