BoomโBox
โโ โโโโโโโโณโโโ โโโโป โป โบโโธโบโโธ โฃโปโโ โโ โโโโโฃโปโโ โโโโ โบโโธโบโโธ โบโโธ โโโโโโโโโโน โนโโโโโโโน โน โบโโธ โญโโโโโโโโโโโโโโโฎ โญโโโโโโโโโโโโฌโโโดโโโโโโโโโโโโโโโดโโโฌโโโโโโโโโโโโฎ โ(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)
โโโโโโโโโโโโโโโโ โฒโโโโโฑโฒโโโโโฑโฒโโโ โโฒโโโโฑโโฒโโโโฑโโฒโโ โโโฒโโโฑโโโฒโโโฑโโโฒโ โโโโฒโโฑโโโโฒโโฑโโโโฒ โโโโโฒโฑโโโโโฒโฑโโโโ โโโโโโโโโโโโโโโโ โโโปโโโ โโโโโโปโโโธ โบโณโโโโโโโธโโโ โปโบโณโธ โโ โโโธโบโณโธโบโณโธโโโธโโโ โป โโโซโ โ โ โโโโซโฃโธ โโโ โโฃโธ โโโ โ โ โฃโปโโฃโธ โ โ โฃโธ โฃโณโ โน โน โนโโโ โโโโน โนโโโธ โบโปโโโโโโโธโโโ โน โน โโโโโโธ โน โน โโโธโนโโธ โน