minimalsound


Nameminimalsound JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
Summary🔊 Play music and sounds in your Python scripts
upload_time2024-03-28 23:43:10
maintainerNone
docs_urlNone
authorAlex DeLorenzo
requires_python>=3.6
licenseLGPL-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": null,
    "name": "minimalsound",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": null,
    "author": "Alex DeLorenzo",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/81/a9/74b4421f414292be3fe71fa4c1fd7510490f991d92dfec02b4b2acb359fb/minimalsound-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": "3e5c8d45ee2ad8b76a86ed50614814cf249958bdc132122e52fbd4334aa3de72",
                "md5": "eb42c32f4683b5f513e4954aedc30435",
                "sha256": "e1eab162f3b3431990f6aaf8f1b3f32ce2c39d2b265df0af0bcf14dde06b728b"
            },
            "downloads": -1,
            "filename": "minimalsound-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "eb42c32f4683b5f513e4954aedc30435",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 8933,
            "upload_time": "2024-03-28T23:43:08",
            "upload_time_iso_8601": "2024-03-28T23:43:08.225683Z",
            "url": "https://files.pythonhosted.org/packages/3e/5c/8d45ee2ad8b76a86ed50614814cf249958bdc132122e52fbd4334aa3de72/minimalsound-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "81a974b4421f414292be3fe71fa4c1fd7510490f991d92dfec02b4b2acb359fb",
                "md5": "1fb9e2b3d754730961855d4a42c39497",
                "sha256": "8eeea26a19e76117a304bb710a87801128e31f2d5f5262863bfe76b627265132"
            },
            "downloads": -1,
            "filename": "minimalsound-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "1fb9e2b3d754730961855d4a42c39497",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 7776,
            "upload_time": "2024-03-28T23:43:10",
            "upload_time_iso_8601": "2024-03-28T23:43:10.341364Z",
            "url": "https://files.pythonhosted.org/packages/81/a9/74b4421f414292be3fe71fa4c1fd7510490f991d92dfec02b4b2acb359fb/minimalsound-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-28 23:43:10",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "minimalsound"
}
        
Elapsed time: 0.24614s