Module soundplayer :: Class SoundPlayer
[hide private]
[frames] | no frames]

Class SoundPlayer

source code

Sound player based on SoX, called "the Swiss Army knife of sound processing programs" by its developper. This simple Python wrapper is based on Linux shell commands running in extra threads. For the Raspberry Pi the following installation are needed: sudo apt-get install sox sudo apt-get install mp3

Instance Methods [hide private]
 
__init__(self, audiofile, device=0)
Creates a sound player to play the given audio file (wav, mp3, etc.) to be played at given device ID.
source code
 
play(self, volume=1, blocking=False)
Plays the sound with given volume (default: 1).
source code
Static Methods [hide private]
 
playTone(frequencies, duration, blocking=False, device=0)
Plays one or several sine tones with given frequencies and duration.
source code
 
isPlaying()
Checks if the sound is still playing.
source code
 
_emit(frequencies, duration, device) source code
 
_run(cmd) source code
 
stop()
Stops playing.
source code
 
pause()
Pauses playing momentarily.
source code
 
resume()
Resumes playing (after it has been stopped).
source code
Method Details [hide private]

playTone(frequencies, duration, blocking=False, device=0)
Static Method

source code 

Plays one or several sine tones with given frequencies and duration.

Parameters:
  • frequencies - the frequency or a list of several frequencies in Hz
  • duration - the duration in s
  • blocking - if True, the functions blocks until playing is finished; otherwise it returns immediately (default: False)
  • device - the sound device ID (e.g. 0: standard device, 1: USB sound adapter)

isPlaying()
Static Method

source code 

Checks if the sound is still playing.

Returns:
True, if the sound is playing; otherwise False

__init__(self, audiofile, device=0)
(Constructor)

source code 

Creates a sound player to play the given audio file (wav, mp3, etc.) to be played at given device ID. Throws exception, if the sound resource is not found.

Parameters:
  • audiofile - the sound file to play
  • device - the sound device ID (e.g. 0: standard device, 1: USB sound adapter)

play(self, volume=1, blocking=False)

source code 

Plays the sound with given volume (default: 1). The function returns immediately.

Parameters:
  • volume - the sound level (default: 1)
  • blocking - if True, the functions blocks until playing is finished; otherwise it returns immediately (default: False)