Fall 2006»Python Media Sound API

Python Media Sound API

Python Media API

Sound I/O

To input an external WAV file into an internal Sound encoding.
Also, to output an internal encoding to an external WAV file.

The following functions manipulate a sound.

Function

Description

pickAFile()

Lets the user pick a file and returns the complete path name as a string.

makeSound(filename)

Takes a filename as input, reads the file, and creates a sound from it. Returns the sound.

makeEmptySound(length)

Creates an empty sound with length samples. Returns the sound.

play(sound)

Plays a sound provided as input. No return value.

blockingPlay(sound)

Plays a sound provided as input and makes sure that no other sound plays at the exact same time. No return value.

writeSoundTo(sound,"file.wav")

Writes sound to the file called "file.wav". Returns nothing.

Definitions

Objects used internally to store external sounds:

  • Sound - an internal encoding of a sound, typically coming from am external WAV file.
  • Sample - a value between -32768 and 32767 in the Sound. This represents the voltage that a microphone would generate (while recording the sound) at the given moment. The duration of this moment is typically 1/44K sec (for CD-quality sound).
  • Samples - a sequence of Sample objects. For example, samples[1] returns the leftmost sample in a sound.

Sound Functions

To access the internal Sound encoding:

getLength(sound)

Returns the number of samples in sound.

getSamplingRate(sound)

Returns the number of samples per second in sound.

getSamples(sound)

Returns a list of samples from sound.

getSampleValueAt(sound,index)

Returns the sample of sound at index.

setSampleValueAt(sound,index,value)

Sets the sample of sound at index to value.