Revision 6:fd0f9d0615b2 2-sndfile-read-and-play.py
| 2-sndfile-read-and-play.py | ||
|---|---|---|
| 28 | 28 |
|
| 29 | 29 |
# extract the number of frames - single samples for |
| 30 | 30 |
# mono and pairs of samples for stereo |
| 31 |
nsamples = f.nframes |
|
| 31 |
num_samples = f.nframes
|
|
| 32 | 32 |
|
| 33 | 33 |
|
| 34 | 34 |
################################################# |
| ... | ... | |
| 36 | 36 |
################################################# |
| 37 | 37 |
|
| 38 | 38 |
# we can read audio samples using the read_frame method |
| 39 |
data = f.read_frames(nsamples)
|
|
| 39 |
samples = f.read_frames(num_samples)
|
|
| 40 | 40 |
|
| 41 | 41 |
|
| 42 | 42 |
################################################# |
| 43 | 43 |
############# PLAYING AN AUDIO FILE ############# |
| 44 | 44 |
################################################# |
| 45 | 45 |
|
| 46 |
# play the audio file data in 'data' at 44100Hz
|
|
| 47 |
play(data,fs=44100)
|
|
| 46 |
# play the audio file data in 'samples' at the sampling frequency 'fs'
|
|
| 47 |
play(samples,fs)
|
|
| 48 | 48 |
|
| 49 | 49 |
|
| 50 | 50 |
################################################# |
Also available in: Unified diff