🔊 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
Built Distribution
File details
Details for the file play_sounds-0.1.3.tar.gz
.
File metadata
- Download URL: play_sounds-0.1.3.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83e2556e2ff52113dc2d1f399b710bd3882a42b1bbaa695921dcb8f2358500d9 |
|
MD5 | f087efcbea968d63e3f254788002fcfd |
|
BLAKE2b-256 | 1b1ba55dad39d5438d10e6557198e36565be7c8e5b862079b898dd9d11eab861 |
Provenance
File details
Details for the file play_sounds-0.1.3-py2.py3-none-any.whl
.
File metadata
- Download URL: play_sounds-0.1.3-py2.py3-none-any.whl
- Upload date:
- Size: 7.5 MB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2539a040b7e24802c9386d8bfa488da2dcab73f7244c7703fbda0f449b5b37a |
|
MD5 | 644b1676557bdf33af6a79311c2dae5b |
|
BLAKE2b-256 | 04ff7dee71652825643d90871d162ecd35daa56985b8408968be7d886d0c4c57 |