A short, cross-platform, pure-python audio file player and tone-generating module.
Project description
┏┓ ┏━┓┏━┓┏┳┓┏┓ ┏━┓╻ ╻ ╺━╸╺━╸ ┣┻┓┃ ┃┃ ┃┃┃┃┣┻┓┃ ┃┏╋┛ ╺━╸╺━╸ ╺━╸ ┗━┛┗━┛┗━┛╹ ╹┗━┛┗━┛╹ ╹ ╺━╸ ╭══════════════╮ ╭───────────┬──┴──────────────┴──┬───────────╮ │(0) ___ │ ⯀ [:::::::] [] ( )│ ___ (0)│ │ /:::::\ │────────────────────│ /:::::\ │ │ |:::::::| │ │ ── ── │ │ |:::::::| │ │ |:::::::| │ │ ─(⚙)────(⚙)─ │ │ |:::::::| │ │ \:::::/ │ │────▯▯▯▯▯▯────│♫ │ \:::::/ │ ╰────────────────────────────────┴───────────╯
This is a small cross-platform audio-file player module, useful for plain-to-fancy system sound events, rings, beeps, and the like. I couldn’t find a good one for this. “playsound” was very close at first glance but had a number of issues and has not been updated in a while.
BoomBox can wait for the file to finish or play in the background. It tries hard to support Windows, Mac, and Linux, and mostly succeeds. Though you could play an eight-minute Grateful Dead jam with it, you probably wouldn’t want to.
Usage
Quick start—a cross-platform player looks like this:
from boombox import BoomBox # power on
boombox = BoomBox("There's_no_stoppin_us.ogg") # load cassette
boombox.play() # hit the ⏯ button
The play function also returns the instance, so if in a hurry one could do:
boombox = BoomBox(slow_jam).play() # or
BoomBox(slow_jam).play()
The latter less efficient for multiple calls, of course. There are a number of other keyword parameters that can be passed. Such as:
wait
timeout_ms
duration_ms
binary_path (ChildBoomBox only, to a CLI player)
Not all arguments are supported on every implementation, but they will not balk if given.
Implementations
There are a number of underlying implementations if you’d like to pick a specific one and bypass the platform default:
Windows
WinBoomBox (default, wav only)
PyAudioBoomBox - PyAudio (wav only)
ChildBoomBox - Command-line player (powershell, others)
Mac OSX:
POSIX:
Simply add an import to your script to choose a different one:
from boombox import PyAudioBoomBox as BoomBox
You may have to install one of the audio libraries above for all of the functionality of Boom Box to work.
⏵ pip install --user boombox[all] # or pyaudio, pyobjc, pygobject, etc
Playback Control
╭───────────────────────────────────────────╮ │ ╭───────────────────────────────────────╮ │ │ │ ╭───────────────────────────────────╮ │ │ │ │ │ /\ : Electric Boogaloo 90 min│ │ │ │ │ │/──\: ..................... NR [✓]│ │ │ │ │ ╰───────────────────────────────────╯ │ │ │ │ //─\\ ╭....:....╮ //─\\ │ │ │ │ ││( )││ │) (│ ││( )││ │ │ │ │ \\─// ╰....:....╯ \\─// │ │ │ │ _ _ ._ _ _ .__|_ _.._ _ │ │ │ │ (_(_)│ |(_(/_│ │_(_||_)(/_ │ │ │ │ low noise | │ │ │ ╰─────── ─────────────────────── ───────╯ │ │ / [] [] \ │ │ / () () \ │ ╰──────/─────────────────────────────\──────╯
A simple playback interface is returned by the instance:
boombox.stop() # Enough!
boombox.play() # One more time!
Tone Generation
Tones may be generated like so:
boombox.play_tone(frequency_hz, duration_ms, volume=.1)
▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂ ╲▂▂▂▂╱╲▂▂▂▂╱╲▂▂▂ ▔╲▂▂▂╱▔╲▂▂▂╱▔╲▂▂ ▔▔╲▂▂╱▔▔╲▂▂╱▔▔╲▂ ▔▔▔╲▂╱▔▔▔╲▂╱▔▔▔╲ ▔▔▔▔╲╱▔▔▔▔╲╱▔▔▔▔ ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ ┏┓╻┏━┓ ┏━┓┏┓╻┏━╸ ╺┳┓┏━┓┏━╸┏━┓ ╻╺┳╸ ┏┓ ┏━╸╺┳╸╺┳╸┏━╸┏━┓ ╻ ┃┗┫┃ ┃ ┃ ┃┃┗┫┣╸ ┃┃┃ ┃┣╸ ┗━┓ ┃ ┃ ┣┻┓┣╸ ┃ ┃ ┣╸ ┣┳┛ ╹ ╹ ╹┗━┛ ┗━┛╹ ╹┗━╸ ╺┻┛┗━┛┗━╸┗━┛ ╹ ╹ ┗━┛┗━╸ ╹ ╹ ┗━╸╹┗╸ ╹
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 boombox-0.56.tar.gz
.
File metadata
- Download URL: boombox-0.56.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/3.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3aa021162a96a8317ff5b94632edaefe4e13731666095be07b133aa0f42da3cf |
|
MD5 | f782c1ca515edd57ead639c0fe703813 |
|
BLAKE2b-256 | 45c37ecdc5bce7fee41413f6a6f2dc811a9353ee25666c16d4bf1d24b4c49188 |
File details
Details for the file boombox-0.56-py2.py3-none-any.whl
.
File metadata
- Download URL: boombox-0.56-py2.py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/3.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f14488865296f527138613cacffb687ff3fa1a5d501c510fe8b1da4d671a568c |
|
MD5 | b64ed1061131a562ef991fed26a977b7 |
|
BLAKE2b-256 | 4c9045fd43f9a71b145d00c7c78b8a7f6d2060590952c889fd2530cd7108edb6 |