Name | minsound JSON |
Version |
0.1.0
JSON |
| download |
home_page | |
Summary | 🔊 Play music and sounds in your Python scripts |
upload_time | 2024-03-18 01:35:01 |
maintainer | |
docs_url | None |
author | Alex DeLorenzo |
requires_python | >=3.6 |
license | LGPL-3.0 |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# 🔊 Play sounds in Python scripts
`minsound` provides a simple cross-platform API to play sounds in Python scripts. It includes a [synchronous API](https://github.com/alexdelorenzo/minsound/blob/main/README.md#synchronous-api) and an equivalent [asynchronous API](https://github.com/alexdelorenzo/minsound/blob/main/README.md#asynchronous-api) that is compatible with `asyncio` and `trio`.
For code examples, you can check out [`onhold`](https://github.com/alexdelorenzo/onhold) and [`ding`](https://github.com/alexdelorenzo/ding), or scroll down to the [Usage section](https://github.com/alexdelorenzo/minsound#usage).
# Why `minsound`?
[`boombox`](https://pypi.org/project/boombox/) is great and 90% of the way there, however it is limited to only playing WAV files on Windows. [`playsound`](https://pypi.org/project/playsound/) will play other formats than WAV on Windows, but it requires GStreamer and `PyGObject` bindings on Linux, while `boombox` has several playback backends for Linux other than, and including, GStreamer.
Neither `boombox` or `playsound` provide `asyncio` and `async/await` compatible APIs, but `minsound` does.
If you're targeting multiple desktop platforms and don't want to get mired down in the details of when and where to use `playsound` or `boombox`, or if your project uses `async/await`, you can just reach for `minsound` and call it a day.
# Installation
```bash
$ python3 -m pip install minsound
```
# Usage
This library uses [`pathlib.Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path) objects when pointing to filenames and paths. It can use [`aiopath.AsyncPath`](https://github.com/alexdelorenzo/aiopath) objects, too.
There's a synchronous API and an [asynchronous API](https://github.com/alexdelorenzo/minsound/blob/main/README.md#asynchronous-api) that you can use with the `async/await` syntax and `asyncio`.
## Synchronous API
### Play a file
```python
from minsound import play_file, DEFAULT_SONG
play_file(DEFAULT_SONG) # blocks by default
# play without blocking
play_file(DEFAULT_SONG, block=False)
```
### Play while work completes
```python
from time import sleep
from minsound import play_while_running, DEFAULT_SONG
WAIT: int = 60
with play_while_running(DEFAULT_SONG):
sleep(WAIT)
```
### Play a file after work completes
```python
from time import sleep
from minsound import play_after, DEFAULT_SOUND
with play_after(DEFAULT_SOUND): # blocks by default
sleep(WAIT)
# play without blocking
with play_after(DEFAULT_SOUND, block=False):
sleep(WAIT)
```
### Ring the [terminal bell](https://en.wikipedia.org/wiki/Bell_character)
```python
from minsound import bell, bell_after
# play bell
bell()
# ensure the bell is played even if an exception is thrown
with bell_after():
raise Exception("Bye")
```
## Asynchronous API
To run the following examples with top-level `await` expressions, [launch an asynchronous Python REPL](https://www.integralist.co.uk/posts/python-asyncio/#running-async-code-in-the-repl) using `python3 -m asyncio` or an [IPython shell](https://ipython.org/).
### Play a file
```python
from minsound import play_file_async, DEFAULT_SONG
await play_file_async(DEFAULT_SONG) # blocks by default
# play without blocking
await play_file_async(DEFAULT_SONG, block=False)
```
### Play while work completes
```python
from asyncio import sleep
from minsound import play_while_running_async, DEFAULT_SONG
async with play_while_running_async(DEFAULT_SONG):
await sleep(WAIT)
```
### Play a file after work completes
```python
from asyncio import sleep
from minsound import play_after_async, DEFAULT_SOUND
async with play_after_async(DEFAULT_SOUND): # blocks by default
await sleep(WAIT)
# play without blocking
async with play_after_async(DEFAULT_SOUND, block=False):
await sleep(WAIT)
```
# Support
Want to support this project and [other open-source projects](https://github.com/alexdelorenzo) like it?
<a href="https://www.buymeacoffee.com/alexdelorenzo" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" height="60px" style="height: 60px !important;width: 217px !important;max-width:25%" ></a>
# Copyright
See `CREDIT.md`.
# License
See `LICENSE`.
Raw data
{
"_id": null,
"home_page": "",
"name": "minsound",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "",
"author": "Alex DeLorenzo",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/d5/ee/1ead7251c8708ee1ee1889f706c5d85373517b65358df0f9e38a7da69eee/minsound-0.1.0.tar.gz",
"platform": null,
"description": "# \ud83d\udd0a Play sounds in Python scripts\n`minsound` provides a simple cross-platform API to play sounds in Python scripts. It includes a [synchronous API](https://github.com/alexdelorenzo/minsound/blob/main/README.md#synchronous-api) and an equivalent [asynchronous API](https://github.com/alexdelorenzo/minsound/blob/main/README.md#asynchronous-api) that is compatible with `asyncio` and `trio`.\n\nFor code examples, you can check out [`onhold`](https://github.com/alexdelorenzo/onhold) and [`ding`](https://github.com/alexdelorenzo/ding), or scroll down to the [Usage section](https://github.com/alexdelorenzo/minsound#usage).\n\n# Why `minsound`?\n[`boombox`](https://pypi.org/project/boombox/) is great and 90% of the way there, however it is limited to only playing WAV files on Windows. [`playsound`](https://pypi.org/project/playsound/) will play other formats than WAV on Windows, but it requires GStreamer and `PyGObject` bindings on Linux, while `boombox` has several playback backends for Linux other than, and including, GStreamer.\n\nNeither `boombox` or `playsound` provide `asyncio` and `async/await` compatible APIs, but `minsound` does.\n\nIf you're targeting multiple desktop platforms and don't want to get mired down in the details of when and where to use `playsound` or `boombox`, or if your project uses `async/await`, you can just reach for `minsound` and call it a day.\n\n# Installation\n```bash\n$ python3 -m pip install minsound\n```\n\n# Usage\nThis library uses [`pathlib.Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path) objects when pointing to filenames and paths. It can use [`aiopath.AsyncPath`](https://github.com/alexdelorenzo/aiopath) objects, too.\n\nThere's a synchronous API and an [asynchronous API](https://github.com/alexdelorenzo/minsound/blob/main/README.md#asynchronous-api) that you can use with the `async/await` syntax and `asyncio`. \n\n## Synchronous API\n### Play a file\n```python\nfrom minsound import play_file, DEFAULT_SONG\n\n\nplay_file(DEFAULT_SONG) # blocks by default\n\n# play without blocking\nplay_file(DEFAULT_SONG, block=False) \n```\n\n### Play while work completes\n```python\nfrom time import sleep\nfrom minsound import play_while_running, DEFAULT_SONG\n\n\nWAIT: int = 60\n\n\nwith play_while_running(DEFAULT_SONG):\n sleep(WAIT)\n```\n\n### Play a file after work completes\n```python\nfrom time import sleep\nfrom minsound import play_after, DEFAULT_SOUND\n\n\nwith play_after(DEFAULT_SOUND): # blocks by default\n sleep(WAIT)\n\n# play without blocking\nwith play_after(DEFAULT_SOUND, block=False):\n sleep(WAIT)\n```\n\n### Ring the [terminal bell](https://en.wikipedia.org/wiki/Bell_character)\n```python\nfrom minsound import bell, bell_after\n\n\n# play bell\nbell()\n\n# ensure the bell is played even if an exception is thrown\nwith bell_after():\n raise Exception(\"Bye\")\n```\n\n## Asynchronous API\nTo run the following examples with top-level `await` expressions, [launch an asynchronous Python REPL](https://www.integralist.co.uk/posts/python-asyncio/#running-async-code-in-the-repl) using `python3 -m asyncio` or an [IPython shell](https://ipython.org/).\n\n### Play a file\n```python\nfrom minsound import play_file_async, DEFAULT_SONG\n\n\nawait play_file_async(DEFAULT_SONG) # blocks by default\n\n# play without blocking\nawait play_file_async(DEFAULT_SONG, block=False) \n```\n\n### Play while work completes\n```python\nfrom asyncio import sleep\nfrom minsound import play_while_running_async, DEFAULT_SONG\n\n\nasync with play_while_running_async(DEFAULT_SONG):\n await sleep(WAIT)\n```\n\n### Play a file after work completes\n```python\nfrom asyncio import sleep\nfrom minsound import play_after_async, DEFAULT_SOUND\n\n\nasync with play_after_async(DEFAULT_SOUND): # blocks by default\n await sleep(WAIT)\n\n# play without blocking\nasync with play_after_async(DEFAULT_SOUND, block=False):\n await sleep(WAIT)\n```\n\n# Support\nWant to support this project and [other open-source projects](https://github.com/alexdelorenzo) like it?\n\n<a href=\"https://www.buymeacoffee.com/alexdelorenzo\" target=\"_blank\"><img src=\"https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png\" alt=\"Buy Me A Coffee\" height=\"60px\" style=\"height: 60px !important;width: 217px !important;max-width:25%\" ></a>\n\n# Copyright\nSee `CREDIT.md`.\n\n# License\nSee `LICENSE`.\n\n\n",
"bugtrack_url": null,
"license": "LGPL-3.0",
"summary": "\ud83d\udd0a Play music and sounds in your Python scripts",
"version": "0.1.0",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "19e77b5854e1789ad793dfd6e1dcce37ddcfbb3909eb9f03bb049237a12b5d5d",
"md5": "48a4cf63b4c728423bd4f9acbc17e7db",
"sha256": "b3d64b8f0a084903d1805c2171053d68193c054b10b85d4b3e8ce8eceffe41ca"
},
"downloads": -1,
"filename": "minsound-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "48a4cf63b4c728423bd4f9acbc17e7db",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 8836,
"upload_time": "2024-03-18T01:34:58",
"upload_time_iso_8601": "2024-03-18T01:34:58.662822Z",
"url": "https://files.pythonhosted.org/packages/19/e7/7b5854e1789ad793dfd6e1dcce37ddcfbb3909eb9f03bb049237a12b5d5d/minsound-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d5ee1ead7251c8708ee1ee1889f706c5d85373517b65358df0f9e38a7da69eee",
"md5": "4648d0c26242500c982fee8941d5e139",
"sha256": "0a18e513ffce36d849af70a5364953a2ea2614ebacc383e64bb71db3825ec524"
},
"downloads": -1,
"filename": "minsound-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "4648d0c26242500c982fee8941d5e139",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 7759,
"upload_time": "2024-03-18T01:35:01",
"upload_time_iso_8601": "2024-03-18T01:35:01.443182Z",
"url": "https://files.pythonhosted.org/packages/d5/ee/1ead7251c8708ee1ee1889f706c5d85373517b65358df0f9e38a7da69eee/minsound-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-18 01:35:01",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "minsound"
}