Module nvwave :: Class WavePlayer
[hide private]
[frames] | no frames]

Class WavePlayer

source code

object --+
         |
        WavePlayer

Synchronously play a stream of audio. To use, construct an instance and feed it waveform audio using feed.

Instance Methods [hide private]
 
__init__(self, channels, samplesPerSec, bitsPerSample, outputDevice=WAVE_MAPPER, closeWhenIdle=True)
Constructor.
source code
 
open(self)
Open the output device.
source code
 
feed(self, data)
Feed a chunk of audio data to be played.
source code
 
sync(self)
Synchronise with playback.
source code
 
pause(self, switch)
Pause or unpause playback.
source code
 
idle(self)
Indicate that this player is now idle; i.e.
source code
 
stop(self)
Stop playback.
source code
 
close(self)
Close the output device.
source code
 
_close(self) source code
 
__del__(self) source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  _global_waveout_lock = threading.RLock()
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, channels, samplesPerSec, bitsPerSample, outputDevice=WAVE_MAPPER, closeWhenIdle=True)
(Constructor)

source code 

Constructor.

Parameters:
  • channels (int) - The number of channels of audio; e.g. 2 for stereo, 1 for mono.
  • samplesPerSec (int) - Samples per second (hz).
  • bitsPerSample (int) - The number of bits per sample.
  • outputDevice (int or basestring) - The device ID or name of the audio output device to use.
  • closeWhenIdle (bool) - If True, close the output device when no audio is being played.
Raises:
  • WindowsError - If there was an error opening the audio output device.
Overrides: object.__init__

Note: If outputDevice is a name and no such device exists, the default device will be used.

open(self)

source code 

Open the output device. This will be called automatically when required. It is not an error if the output device is already open.

feed(self, data)

source code 

Feed a chunk of audio data to be played. This is normally synchronous. However, synchronisation occurs on the previous chunk, rather than the current chunk; i.e. calling this while no audio is playing will begin playing the chunk but return immediately. This allows for uninterrupted playback as long as a new chunk is fed before the previous chunk has finished playing.

Parameters:
  • data (str) - Waveform audio in the format specified when this instance was constructed.
Raises:
  • WindowsError - If there was an error playing the audio.

sync(self)

source code 

Synchronise with playback. This method blocks until the previously fed chunk of audio has finished playing. It is called automatically by feed, so usually need not be called directly by the user.

pause(self, switch)

source code 

Pause or unpause playback.

Parameters:
  • switch (bool) - True to pause playback, False to unpause.

idle(self)

source code 

Indicate that this player is now idle; i.e. the current continuous segment of audio is complete. This will first call sync to synchronise with playback. If closeWhenIdle is True, the output device will be closed. A subsequent call to feed will reopen it.