🔊 Play music and sounds in your Python scripts
Project description
Play sounds in your Python scripts
This project provides a simple cross-platform API to play sounds in your Python scripts, and allows you to play sounds while a function or code block executes, or afterwards.
It's a simple wrapper over playsound
and boombox
.
I use this project in onhold
and ding
.
Rationale
boombox
is great and 90% of the way there, however the default options for playing sounds on Windows are limited to WAV files. If the platform is Windows, play_sounds
will default to the playsound
backend.
Installation
python3 -m pip install play_sounds
Usage
This library uses pathlib.Path
objects when pointing to filenames and paths.
Playing a file
from play_sounds import play_file, DEFAULT_SONG
play_file(DEFAULT_SONG) # blocks by default
# play without blocking
play_file(DEFAULT_SONG, block=False)
Playing while work completes
from time import sleep
from play_sounds import play_while_running, DEFAULT_SONG
with play_while_running(DEFAULT_SONG):
sleep(60)
Play sound after work completes
from time import sleep
from play_sounds import play_after, DEFAULT_SOUND
with play_after(DEFAULT_SOUND): # blocks by default
sleep(60)
# play without blocking
with play_after(DEFAULT_SOUND, block=False):
sleep(60)
Copyright
See CREDIT.md
.
License
See LICENSE
.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
play_sounds-0.1.2.tar.gz
(3.5 kB
view hashes)
Built Distribution
Close
Hashes for play_sounds-0.1.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92ab00e28678c3b01a574efe068e34d5bf468ac210bd48a6b14b5ac92f7a48d5 |
|
MD5 | 5d1b7226b29103e982aff99b15b83f91 |
|
BLAKE2b-256 | d9f00e4d2dbbad97ebb42430744c2b2ff14f36c2f8980d2f709ac9d873fd4e09 |