Skip to main content

Cross-platform library to play audio files

Project description

playsound3

PyPi version PyPI license

Cross platform library to play sound files in Python.

Installation

Install via pip:

pip install playsound3

Quick Start

Once installed, you can use the playsound function to play sound files:

from playsound3 import playsound

playsound("/path/to/sound/file.mp3")

# or use directly on URLs
playsound("http://url/to/sound/file.mp3")

Documentation

The playsound3 module contains a single function named playsound:

def playsound(
        sound: str | Path,
        block: bool = True,
        backend: str | None = None,
        daemon: bool = True,
    ) -> Thread | None:
    """Play a sound file using an audio backend availabile in your system.

    Args:
        sound: Path or URL to the sound file. Can be a string or pathlib.Path.
        block: If True, the function will block execution until the sound finishes playing.
               If False, sound will play in a background thread.
        backend: Name of the audio backend to use. Use None for automatic selection.
        daemon: If True, and `block` is True, the background thread will be a daemon thread.
                This means that the thread will stay alive even after the main program exits.

    Returns:
        If `block` is True, the function will return None after the sound finishes playing.
        If `block` is False, the function will return the background thread object.

    """
    ...

It requires one argument: sound - the path to the file with the sound you'd like to play. This should be a local file or a URL. There's an optional second argument: block which is set to True by default. Setting it to False makes the function run asynchronously. You can manually specify a backend by passing its name as the third argument. You can browse available backends by using playsound3.AVAILABLE_BACKENDS. It is recommended to use the default value of None to let the library choose the best backend available.

Supported systems

  • Linux using one of the below backends, whichever is available:
    • GStreamer
    • FFmpeg
    • aplay for .wav and mpg123 .mp3
  • Windows using winmm.dll (built-in on Windows)
  • macOS using afplay utility (built-in on macOS)

Fork information

This repository was originally forked from playsound library created by Taylor Marks. The original library is unfortunately not maintained anymore and doesn't accept pull requests. This library: playsound3 is a major rewrite of the original, including its own set of tests hosted using GitHub Actions.

Compared to the original, playsound3:

  • Drops support for Python 2
  • Adheres to the latest PEP standards
  • Offers multiple backends with a fallback mechanism if the default backend is not available
  • Accepts contributions

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

playsound3-2.5.0.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

playsound3-2.5.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file playsound3-2.5.0.tar.gz.

File metadata

  • Download URL: playsound3-2.5.0.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for playsound3-2.5.0.tar.gz
Algorithm Hash digest
SHA256 67baba0bfa41b8a53bf2f2bd2ac42787c977253afc94323d8dcfe1ca0f4dfd66
MD5 e63ba9e1de41c14b7ca4075cd8e854d9
BLAKE2b-256 5d6cc294106d59be8971dc22b1a471654a8b7046cb1e8173272b8ca251f5b9df

See more details on using hashes here.

File details

Details for the file playsound3-2.5.0-py3-none-any.whl.

File metadata

  • Download URL: playsound3-2.5.0-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for playsound3-2.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8b2d8bfd7ca00a91d6529458b3fe8a4912fbb83e431f4d4bc86ef83f4f6ed2e1
MD5 8cd282167ed2644e8272c135a87963e0
BLAKE2b-256 c7c4ea576e6136e556cde3b8ef7f1d8fdc30d0a0186c1b45b6177d0b324dd577

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page