Skip to main content

🔊 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


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.3.1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

play_sounds-0.3.1-py2.py3-none-any.whl (7.5 MB view details)

Uploaded Python 2Python 3

File details

Details for the file play_sounds-0.3.1.tar.gz.

File metadata

  • Download URL: play_sounds-0.3.1.tar.gz
  • Upload date:
  • Size: 4.2 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

Hashes for play_sounds-0.3.1.tar.gz
Algorithm Hash digest
SHA256 a9db2025f699e7ec9a80315dd4a7f0ad513bdf9d6bf8b949e2dcff4b022112cc
MD5 d31b9dd59a60faf92353bd9a0e45e007
BLAKE2b-256 e0f61c3db26e4297d87f983f1298eb3873d2780e13c84f28cb2a488d8e67115b

See more details on using hashes here.

File details

Details for the file play_sounds-0.3.1-py2.py3-none-any.whl.

File metadata

  • Download URL: play_sounds-0.3.1-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

Hashes for play_sounds-0.3.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 0330bf4df3a80634f07e43e793e578775348296a62b73f6c27b56a0577c38b1a
MD5 d86ba3ececcfff0e78a0fa26d0493cec
BLAKE2b-256 24f855cb954fa76028c7fecf3ba0bb7bdd2cf4d60b26ccf5672372dddeeab1dc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page