Chapter 19

Sound Manipulation

Sounds are represented in computer memory as a sequence of discrete samples of air pressure readings. CDs are recorded using 44,100 of these samples per second. With that many samples, it is possible to reconstruct the original sound waves in such a way that our ears have a difficult time hearing any difference between the reproduction and the original sound. Given access to those samples in a Python program, we can do some interesting things.

Listing 19.1: Reverse WAV

 1 #
 2 import array
 3 import contextlib
 4 import wave
 6 def datatype(width):
 7 return "B" if width == 1 else "h"
 9 def readwav(fname):
10 with contextlib.closing( as f:
11  params = f.getparams()
12  frames ...

Get A Concise Introduction to Programming in Python now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.