Sound#
The wolpie.sound package provides simple utilities for playing sound files.
Functions#
play_sound#
This function is based on the work done by playsound. I didn’t like the way it was structured, so I rewrote it to fit my needs. Currently, it only supports Windows, but I plan to add support for other platforms in the future.
I required a lightweight way to play sound files so that I could use it in my ding context manager.
- wolpie.sound.play_sound(sound, block=True)#
A function that will play *.mp3 and *.wav sound files.
Warning
This function is only officially supported on Windows.
Example usage:
from wolpie import play_sound # or from wolpie.sound import play_sound play_sound("path/to/sound/file.mp3")
Tip
If you want sound files, consider https://pixabay.com/sound-effects/search
- Parameters:
sound (str | Path) – The sound file to play.
block (bool) – If True, the function will block until the sound has finished playing.
- Raises:
PlaySoundError – If there was an error playing the sound.
- Return type:
None
ding#
A context manager that plays a sound when the block of code inside it is done executing. By default, it plays a “ding” sound included with Wolpie, but you can specify your own
- wolpie.sound.ding(sound=PosixPath('/home/runner/work/wolpie/wolpie/src/wolpie/sound/ding.mp3'))[source]#
A context manager that plays a “ding” sound when the block of code inside the context manager finishes executing.
If if fails to play the “ding”, it won’t raise any errors. After all.. the whole idea of this context manager is to notify you when a long running function is done. Imagine you wait 2 hours just for the nice sound file to fail. And you have to start from scratch. No thanks.
Warning
This function is only officially supported on Windows.
Uses
play_sound()under the hood.Example usage:
from wolpie import ding import time # plays the default "ding" sound after the block finishes with ding(): time.sleep(10) # Simulate some long running function # or if you have a cooler ding: with ding("path/to/cooler/ding.mp3"): time.sleep(10) # Simulate some long running function
Tip
If you want sound files, consider https://pixabay.com/sound-effects/search
- Parameters:
sound (str | Path) – The sound file to play. Defaults to a built-in “ding” sound.
- Yield Generator[None, None, None]:
Yields nothing.
- Return type:
Generator[None,None,None]