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 / 2-sndfile-read-and-play.py @ 6:fd0f9d0615b2

History | View | Annotate | Download (1.47 KB)

1
from scikits.audiolab import Sndfile
2
from scikits.audiolab import Format
3
from scikits.audiolab import play
4

    
5
#################################################
6
######## CREATING A SOUND FILE INSTANCE #########
7
#################################################
8

    
9
# create Sndfile instance with our example audio file
10
f = Sndfile('viola.wav', 'r')
11

    
12

    
13
#################################################
14
######## EXTRACTING AUDIO FILE META-DATA ########
15
#################################################
16

    
17
# extract and print sample rate
18
fs = f.samplerate
19
print "sample rate: ",fs
20

    
21
# extract and print the number of channels
22
nc = f.channels
23
print "number of channels: ",nc
24

    
25
# extract and print the encoding format
26
enc = f.encoding
27
print "encoding format: ",enc
28

    
29
# extract the number of frames - single samples for
30
# mono and pairs of samples for stereo
31
num_samples = f.nframes
32

    
33

    
34
#################################################
35
######## READ AUDIO SAMPLES FROM THE FILE #######
36
#################################################
37

    
38
# we can read audio samples using the read_frame method
39
samples = f.read_frames(num_samples)
40

    
41

    
42
#################################################
43
############# PLAYING AN AUDIO FILE #############
44
#################################################
45

    
46
# play the audio file data in 'samples' at the sampling frequency 'fs' 
47
play(samples,fs)
48

    
49

    
50
#################################################
51
#################################################
52
#################################################