playsound3 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- playsound3-2.0.0/LICENSE +33 -0
- playsound3-2.0.0/PKG-INFO +67 -0
- playsound3-2.0.0/README.md +42 -0
- playsound3-2.0.0/playsound3/__init__.py +1 -0
- playsound3-2.0.0/playsound3/playsound3.py +115 -0
- playsound3-2.0.0/playsound3.egg-info/PKG-INFO +67 -0
- playsound3-2.0.0/playsound3.egg-info/SOURCES.txt +11 -0
- playsound3-2.0.0/playsound3.egg-info/dependency_links.txt +1 -0
- playsound3-2.0.0/playsound3.egg-info/requires.txt +3 -0
- playsound3-2.0.0/playsound3.egg-info/top_level.txt +1 -0
- playsound3-2.0.0/pyproject.toml +13 -0
- playsound3-2.0.0/setup.cfg +4 -0
- playsound3-2.0.0/setup.py +41 -0
playsound3-2.0.0/LICENSE
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Taylor Marks <taylor@marksfam.com>
|
|
4
|
+
Copyright (c) 2024 Szymon Mikler <sjmikler@gmail.com>
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
23
|
+
|
|
24
|
+
##################################################################
|
|
25
|
+
|
|
26
|
+
Files used for Unit Tests were downloaded from Wikimedia Commons - they and their licenses can be found at the following urls.
|
|
27
|
+
I am not a lawyer, but it's my belief that as these files are merely used for unit testing and in no way necessary for using
|
|
28
|
+
playsound that playsound can be distributed under the more permissive (supperior, actual free) MIT license and that the
|
|
29
|
+
cancerous copyleft bullshit from the Creative Commons licenses that most of the files have:
|
|
30
|
+
- https://commons.wikimedia.org/wiki/File:Damonte.mp3
|
|
31
|
+
- https://commons.wikimedia.org/wiki/File:Sound4.wav
|
|
32
|
+
- https://commons.wikimedia.org/wiki/File:%D0%91%D1%83%D0%BA%D0%B2%D0%B0_%D0%AF.wav
|
|
33
|
+
- https://commons.wikimedia.org/wiki/File:Discovery_-_Go_at_throttle_up_(2).mp3
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: playsound3
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: Cross-platform library to play audio files
|
|
5
|
+
Home-page: https://github.com/sjmikler/playsound3
|
|
6
|
+
Author: Szymon Mikler
|
|
7
|
+
Author-email: sjmikler@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Keywords: sound playsound music wave wav mp3 media song play audio
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Topic :: Multimedia :: Sound/Audio :: MIDI
|
|
19
|
+
Classifier: Topic :: Multimedia :: Sound/Audio :: Players
|
|
20
|
+
Classifier: Topic :: Multimedia :: Sound/Audio :: Players :: MP3
|
|
21
|
+
Requires-Python: >=3.7
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: pygobject; platform_system == "Linux"
|
|
25
|
+
|
|
26
|
+
> This repository was initially forked from [TaylorSMarks/playsound](https://github.com/TaylorSMarks/playsound/blob/master/playsound.py)
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
Install via pip:
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
pip install playsound3
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Quick Start
|
|
37
|
+
|
|
38
|
+
Once installed, you can use the playsound function to play sound files:
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from playsound3 import playsound
|
|
42
|
+
|
|
43
|
+
playsound("/path/to/sound/file.mp3")
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Documentation
|
|
47
|
+
|
|
48
|
+
The playsound module contains only one thing - the function (also named) playsound:
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
def playsound(sound: os.PathLike, block: bool = True) -> None:
|
|
52
|
+
"""Play a sound file using an audio player availabile on your system.
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
sound: Path to the sound file.
|
|
56
|
+
block: If True, the function will block execution until the sound finishes playing.
|
|
57
|
+
"""
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
It requires one argument - the path to the file with the sound you'd like to play. This may be a local file, or a URL.
|
|
61
|
+
There's an optional second argument, block, which is set to True by default. Setting it to False makes the function run asynchronously.
|
|
62
|
+
|
|
63
|
+
## Supported systems
|
|
64
|
+
|
|
65
|
+
* Linux, using GStreamer (built-in on Linux distributions)
|
|
66
|
+
* Windows, using windll.winmm (built-in on Windows)
|
|
67
|
+
* OS X using afplay utility (built-in OS X)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
> This repository was initially forked from [TaylorSMarks/playsound](https://github.com/TaylorSMarks/playsound/blob/master/playsound.py)
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
Install via pip:
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
pip install playsound3
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
Once installed, you can use the playsound function to play sound files:
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from playsound3 import playsound
|
|
17
|
+
|
|
18
|
+
playsound("/path/to/sound/file.mp3")
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Documentation
|
|
22
|
+
|
|
23
|
+
The playsound module contains only one thing - the function (also named) playsound:
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
def playsound(sound: os.PathLike, block: bool = True) -> None:
|
|
27
|
+
"""Play a sound file using an audio player availabile on your system.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
sound: Path to the sound file.
|
|
31
|
+
block: If True, the function will block execution until the sound finishes playing.
|
|
32
|
+
"""
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
It requires one argument - the path to the file with the sound you'd like to play. This may be a local file, or a URL.
|
|
36
|
+
There's an optional second argument, block, which is set to True by default. Setting it to False makes the function run asynchronously.
|
|
37
|
+
|
|
38
|
+
## Supported systems
|
|
39
|
+
|
|
40
|
+
* Linux, using GStreamer (built-in on Linux distributions)
|
|
41
|
+
* Windows, using windll.winmm (built-in on Windows)
|
|
42
|
+
* OS X using afplay utility (built-in OS X)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from playsound3.playsound3 import playsound
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import ctypes
|
|
2
|
+
import logging
|
|
3
|
+
import os
|
|
4
|
+
import subprocess
|
|
5
|
+
import uuid
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from platform import system
|
|
8
|
+
from threading import Thread
|
|
9
|
+
from urllib.request import pathname2url
|
|
10
|
+
|
|
11
|
+
logger = logging.getLogger(__name__)
|
|
12
|
+
|
|
13
|
+
SYSTEM = system()
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class PlaysoundException(Exception):
|
|
17
|
+
pass
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def playsound(sound: os.PathLike, block: bool = True) -> None:
|
|
21
|
+
"""Play a sound file using an audio player availabile on your system.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
sound: Path to the sound file.
|
|
25
|
+
block: If True, the function will block execution until the sound finishes playing.
|
|
26
|
+
"""
|
|
27
|
+
sound = _prepare_path(sound)
|
|
28
|
+
|
|
29
|
+
if SYSTEM == "Linux":
|
|
30
|
+
func = _playsound_gstreamer
|
|
31
|
+
elif SYSTEM == "Windows":
|
|
32
|
+
func = _playsound_winmm
|
|
33
|
+
elif SYSTEM == "Darwin":
|
|
34
|
+
func = _playsound_afplay
|
|
35
|
+
else:
|
|
36
|
+
raise PlaysoundException(f"Platform '{SYSTEM}' is not supported")
|
|
37
|
+
|
|
38
|
+
if block:
|
|
39
|
+
func(sound)
|
|
40
|
+
else:
|
|
41
|
+
t = Thread(target=func, args=(sound,)).start()
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _prepare_path(sound):
|
|
45
|
+
path = Path(sound)
|
|
46
|
+
|
|
47
|
+
if not path.exists():
|
|
48
|
+
raise PlaysoundException(f"File not found: {sound}")
|
|
49
|
+
|
|
50
|
+
return path.absolute().as_posix()
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _playsound_gstreamer(sound):
|
|
54
|
+
"""Play a sound using gstreamer (built-in Linux)."""
|
|
55
|
+
|
|
56
|
+
if not sound.startswith(("http://", "https://", "file://")):
|
|
57
|
+
path = os.path.abspath(sound)
|
|
58
|
+
if not os.path.exists(path):
|
|
59
|
+
raise PlaysoundException(f"File not found: {path}")
|
|
60
|
+
sound = "file://" + pathname2url(path)
|
|
61
|
+
|
|
62
|
+
import gi
|
|
63
|
+
|
|
64
|
+
# Silences gi warning
|
|
65
|
+
gi.require_version("Gst", "1.0")
|
|
66
|
+
|
|
67
|
+
# GStreamer is included in all Linux distributions
|
|
68
|
+
from gi.repository import Gst
|
|
69
|
+
|
|
70
|
+
Gst.init(None)
|
|
71
|
+
|
|
72
|
+
playbin = Gst.ElementFactory.make("playbin", "playbin")
|
|
73
|
+
playbin.props.uri = sound
|
|
74
|
+
|
|
75
|
+
logger.debug("gstreamer: starting playing %s", sound)
|
|
76
|
+
set_result = playbin.set_state(Gst.State.PLAYING)
|
|
77
|
+
if set_result != Gst.StateChangeReturn.ASYNC:
|
|
78
|
+
raise PlaysoundException("playbin.set_state returned " + repr(set_result))
|
|
79
|
+
bus = playbin.get_bus()
|
|
80
|
+
try:
|
|
81
|
+
bus.poll(Gst.MessageType.EOS, Gst.CLOCK_TIME_NONE)
|
|
82
|
+
finally:
|
|
83
|
+
playbin.set_state(Gst.State.NULL)
|
|
84
|
+
logger.debug("gstreamer: finishing play %s", sound)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _send_winmm_mci_command(command):
|
|
88
|
+
winmm = ctypes.WinDLL("winmm.dll")
|
|
89
|
+
buffer = ctypes.create_string_buffer(255)
|
|
90
|
+
error_code = winmm.mciSendStringA(ctypes.c_char_p(command.encode()), buffer, 254, 0)
|
|
91
|
+
if error_code:
|
|
92
|
+
logger.error("Error code: %s", error_code)
|
|
93
|
+
return buffer.value
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _playsound_winmm(sound):
|
|
97
|
+
"""Play a sound utilizing windll.winmm."""
|
|
98
|
+
|
|
99
|
+
# Select a unique alias for the sound
|
|
100
|
+
alias = str(uuid.uuid4())
|
|
101
|
+
logger.debug("winmm: starting playing %s", sound)
|
|
102
|
+
_send_winmm_mci_command(f'open "{sound}" type mpegvideo alias {alias}')
|
|
103
|
+
_send_winmm_mci_command(f"play {alias} wait")
|
|
104
|
+
_send_winmm_mci_command(f"close {alias}")
|
|
105
|
+
logger.debug("winmm: finishing play %s", sound)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def _playsound_afplay(sound):
|
|
109
|
+
"""Uses afplay utility (built-in macOS)."""
|
|
110
|
+
logger.debug("afplay: starting playing %s", sound)
|
|
111
|
+
try:
|
|
112
|
+
subprocess.run(["afplay", sound], check=True)
|
|
113
|
+
except subprocess.CalledProcessError as e:
|
|
114
|
+
raise PlaysoundException(f"afplay failed to play sound: {e}")
|
|
115
|
+
logger.debug("afplay: finishing play %s", sound)
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: playsound3
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: Cross-platform library to play audio files
|
|
5
|
+
Home-page: https://github.com/sjmikler/playsound3
|
|
6
|
+
Author: Szymon Mikler
|
|
7
|
+
Author-email: sjmikler@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Keywords: sound playsound music wave wav mp3 media song play audio
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Topic :: Multimedia :: Sound/Audio :: MIDI
|
|
19
|
+
Classifier: Topic :: Multimedia :: Sound/Audio :: Players
|
|
20
|
+
Classifier: Topic :: Multimedia :: Sound/Audio :: Players :: MP3
|
|
21
|
+
Requires-Python: >=3.7
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: pygobject; platform_system == "Linux"
|
|
25
|
+
|
|
26
|
+
> This repository was initially forked from [TaylorSMarks/playsound](https://github.com/TaylorSMarks/playsound/blob/master/playsound.py)
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
Install via pip:
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
pip install playsound3
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Quick Start
|
|
37
|
+
|
|
38
|
+
Once installed, you can use the playsound function to play sound files:
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from playsound3 import playsound
|
|
42
|
+
|
|
43
|
+
playsound("/path/to/sound/file.mp3")
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Documentation
|
|
47
|
+
|
|
48
|
+
The playsound module contains only one thing - the function (also named) playsound:
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
def playsound(sound: os.PathLike, block: bool = True) -> None:
|
|
52
|
+
"""Play a sound file using an audio player availabile on your system.
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
sound: Path to the sound file.
|
|
56
|
+
block: If True, the function will block execution until the sound finishes playing.
|
|
57
|
+
"""
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
It requires one argument - the path to the file with the sound you'd like to play. This may be a local file, or a URL.
|
|
61
|
+
There's an optional second argument, block, which is set to True by default. Setting it to False makes the function run asynchronously.
|
|
62
|
+
|
|
63
|
+
## Supported systems
|
|
64
|
+
|
|
65
|
+
* Linux, using GStreamer (built-in on Linux distributions)
|
|
66
|
+
* Windows, using windll.winmm (built-in on Windows)
|
|
67
|
+
* OS X using afplay utility (built-in OS X)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
setup.py
|
|
5
|
+
playsound3/__init__.py
|
|
6
|
+
playsound3/playsound3.py
|
|
7
|
+
playsound3.egg-info/PKG-INFO
|
|
8
|
+
playsound3.egg-info/SOURCES.txt
|
|
9
|
+
playsound3.egg-info/dependency_links.txt
|
|
10
|
+
playsound3.egg-info/requires.txt
|
|
11
|
+
playsound3.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
playsound3
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
from setuptools import find_packages, setup
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def package_relative_path(path):
|
|
7
|
+
return Path(__file__).parent / path
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
long_description = package_relative_path("README.md").read_text(encoding="UTF-8")
|
|
11
|
+
|
|
12
|
+
setup(
|
|
13
|
+
name="playsound3",
|
|
14
|
+
version="2.0.0",
|
|
15
|
+
description="Cross-platform library to play audio files",
|
|
16
|
+
url="https://github.com/sjmikler/playsound3",
|
|
17
|
+
author="Szymon Mikler",
|
|
18
|
+
author_email="sjmikler@gmail.com",
|
|
19
|
+
license="MIT",
|
|
20
|
+
classifiers=[
|
|
21
|
+
"License :: OSI Approved :: MIT License",
|
|
22
|
+
"Operating System :: OS Independent",
|
|
23
|
+
"Intended Audience :: Developers",
|
|
24
|
+
"Programming Language :: Python :: 3",
|
|
25
|
+
"Programming Language :: Python :: 3.9",
|
|
26
|
+
"Programming Language :: Python :: 3.10",
|
|
27
|
+
"Programming Language :: Python :: 3.11",
|
|
28
|
+
"Programming Language :: Python :: 3.12",
|
|
29
|
+
"Topic :: Multimedia :: Sound/Audio :: MIDI",
|
|
30
|
+
"Topic :: Multimedia :: Sound/Audio :: Players",
|
|
31
|
+
"Topic :: Multimedia :: Sound/Audio :: Players :: MP3",
|
|
32
|
+
],
|
|
33
|
+
keywords="sound playsound music wave wav mp3 media song play audio",
|
|
34
|
+
packages=find_packages(),
|
|
35
|
+
python_requires=">=3.7",
|
|
36
|
+
install_requires=[
|
|
37
|
+
"pygobject; platform_system=='Linux'",
|
|
38
|
+
],
|
|
39
|
+
long_description=long_description,
|
|
40
|
+
long_description_content_type="text/markdown",
|
|
41
|
+
)
|