wx.Sound

Inheritance diagram for wx.Sound:



Description

This class represents a short sound (loaded from Windows WAV file), that can be stored in memory and played.

Currently this class is implemented on Windows and Unix (and uses either Open Sound System or Simple DirectMedia Layer).

Derived From

Class API

Methods

__init__(fileName="")

Constructs a wave object from a file. Call IsOk to determine whether this succeeded.

Parameters:

  • fileName (string): The filename.

Returns:

wx.Sound


Create(fileName)

Constructs a wave object from a file.

Returns True if the call was successful, False otherwise.

Parameters:

  • fileName (string): The filename.

Returns:

bool


CreateFromData(data)

Parameters:

  • data (PyObject)

Returns:

bool


IsOk()

Returns True if the object contains a successfully loaded file or resource, False otherwise.


Returns:

bool


Play(flags=wx.SOUND_ASYNC)

Plays the sound file. If another sound is playing, it will be interrupted.

Returns True on success, False otherwise.

Parameters:

  • flags (int): The possible values for flags are:

    Sound Flags

    Description

    wx.SOUND_SYNC

    Play will block and wait until the sound is replayed.

    wx.SOUND_ASYNC

    Sound is played asynchronously, Play returns immediately.

    wx.SOUND_ASYNC | wx.SOUND_LOOP

    Sound is played asynchronously and loops until another sound is played, Stop is called or the program terminates.


Returns:

bool

Note

Note that in general it is possible to delete the object which is being asynchronously played any time after calling this function and the sound would continue playing, however this currently doesn’t work under Windows for sound objects loaded from memory data.


PlaySound(filename, flags=wx.SOUND_ASYNC)

Plays the sound from the file filename. If another sound is playing, it will be interrupted.

Returns True on success, False otherwise.

Parameters:

  • filename (string): the file name to play.
  • flags (int): see Play for the flags explanation.

Stop()
If a sound is played, this function stops it.