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

Statistics Download as Zip
| Branch: | Revision:

root / audio_io.py @ 0:ea12496723d2

History | View | Annotate | Download (894 Bytes)

1
# imports audiolab
2
import scikits.audiolab as audiolab
3

    
4
# create Sndfile instance with our example audio file
5
f = audiolab.Sndfile('viola.wav', 'r')
6

    
7
#################
8
## Extracting metadata from audio file
9
#################
10

    
11
# sample rate
12
fs = f.samplerate
13
print "Sample rate: ", fs
14

    
15
# number of channels
16
nc = f.channels
17
print "Number of channels: ", nc
18

    
19
# encoding format
20
enc = f.encoding
21
print "Encoding format: ", enc
22

    
23
# number of frames - single samples for
24
# mono and pairs of samples for stereo
25
num_samples = f.nframes
26

    
27
#################
28
## Reading Audio Samples from the file
29
#################
30

    
31
# We can read audio samples using the read_frame method
32
samples = f.read_frames(num_samples)
33

    
34
# We can now close the file...
35
f.close()
36

    
37
#################
38
## Playing the audio
39
#################
40

    
41
# play the audio file data in 'samples' at the sampling frequency 'fs'
42
audiolab.play(samples,fs)