resources/send_message_and_files/sound_player.py

This module is used to play audio files on WinOS or TOS and contains two classes:

  • SoundPlayer - for normal sound playback.
  • SoundQueuePlayer - to play sounds in queue.

The difference is that, using the SoundPlayer class, audio files will interrupt each other when played in a row. And when using the SoundQueuePlayer class, files are played in queue.

For correct playback, all audio files must be in * .wav format

SoundPlayer

Class attributes:

  • sounds_dir (List[str]): List of directories with audio files. By default, contains the path to standard audio files of Trassir.

Class methods:

  • play(sound) - plays the audio file.
    Method arguments:
    • sound(str)The absolute path to the sound file or the path relative to one of the folders in the sounds_dir parameter.

SoundQueuePlayer

Class arguments:

  • maxlen (int, optional): Maximum queue length for playback. 10 by default.

SoundQueuePlayer inherits from the SoundPlayer class, so attributes and methods are the same.

Code examples:

Playing a standard bell.wav sound file

from sound_player import SoundPlayer

sp = SoundPlayer()

sp.play("bell.wav")

Playing audio files one by one in a queue

from sound_player import SoundQueuePlayer

sp = SoundQueuePlayer()
sp.play("bell.wav")
sp.play("bell.wav")
sp.play("bell.wav")


  • Нет меток