Skip to Content
A Concise Introduction to Programming in Python
book

A Concise Introduction to Programming in Python

by Mark J. Johnson
December 2011
Beginner
217 pages
8h
English
Chapman and Hall/CRC
Content preview from A Concise Introduction to Programming in Python
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 # reversewav.py
2 import array
3 import contextlib
4 import wave
5
6 def datatype(width):
7 return "B" if width == 1 else "h"
8
9 def readwav(fname):
10 with contextlib.closing(wave.open(fname)) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python Standard Library

Python Standard Library

Fredrik Lundh
Numerical Computing with Python

Numerical Computing with Python

Pratap Dangeti, Allen Yu, Claire Chung, Aldrin Yim

Publisher Resources

ISBN: 9781439896952