To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

The primary repository for this project is hosted at https://github.com/Codasign/york-software-bootcamp-audio-day.git .
This repository is a read-only copy which is updated automatically every hour.

Statistics Download as Zip
| Branch: | Revision:

root / synthesize-mono-noise-with-numpy.py @ 2:7b9a06f64ab1

History | View | Annotate | Download (961 Bytes)

1
import numpy as np
2
from scikits.audiolab import Sndfile
3
from scikits.audiolab import Format
4

    
5

    
6
#################################################
7
############ CREATE SOME RANDOM NOISE ###########
8
#################################################
9

    
10
# set our sampling frequency
11
fs = 44100
12

    
13
# create a numpy array that can hold 3 seconds of sound
14
noise = np.empty(3*fs)
15

    
16
# set each element to a random value (noise)
17
for i in range(noise.size):
18
    # generate random value and turn it down!
19
    noise[i] = np.random.random()*0.2
20

    
21

    
22
#################################################
23
########## WRITING NOISE TO AUDIO FILE ##########
24
#################################################
25

    
26
# create a name for the new file
27
new_filename = 'noise.wav'
28

    
29
# Create a Sndfile instance for writing wav files @ 44100 Hz
30
format = Format('wav')
31
f = Sndfile(new_filename, 'w', format, 1, fs)
32

    
33
# Write out the samples to the file
34
f.write_frames(noise)
35

    
36
# close the audio file
37
f.close()
38