Revision 6:fd0f9d0615b2 3-sndfile-write.py
| 3-sndfile-write.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 |
################################################# |
| ... | ... | |
| 47 | 47 |
new_filename = 'output_file.wav' |
| 48 | 48 |
|
| 49 | 49 |
# create the output audio data, in this case a simple copy |
| 50 |
output_data = data
|
|
| 50 |
output_samples = samples
|
|
| 51 | 51 |
|
| 52 | 52 |
# Create a Sndfile instance for writing wav files @ 44100 Hz |
| 53 | 53 |
format = Format('wav')
|
| 54 | 54 |
f = Sndfile(new_filename, 'w', format, 1, 44100) |
| 55 | 55 |
|
| 56 | 56 |
# Write out the first 3 seconds worth of samples (fs*3) |
| 57 |
f.write_frames(output_data[:fs*3])
|
|
| 57 |
f.write_frames(output_samples)
|
|
| 58 | 58 |
|
| 59 | 59 |
# close the audio file |
| 60 | 60 |
f.close() |
Also available in: Unified diff