Skip to main content

Cross-platform library to play audio files

Project description

Version 3.0.0

New functionalities:

  • stop sounds by calling sound.stop()
  • check if sound is still playing with sound.is_alive()

playsound3

PyPi version PyPI license

Cross platform library to play sound files in Python.

Installation

Install via pip:

pip install playsound3

Quick Start

After installation, playing sounds is simple:

from playsound3 import playsound

# Play sounds from disk
playsound("/path/to/sound/file.mp3")

# or play sounds from the internet.
playsound("http://url/to/sound/file.mp3")

# You can play sounds in the background
sound = playsound("/path/to/sound/file.mp3", block=False)

# and check if they are still playing
if sound.is_alive():
    print("Sound is still playing!")

# and stop them whenever you like.
sound.stop()

Reference

playsound

def playsound(
    sound: str | Path,
    block: bool = True,
    backend: str | None = None,
) -> Sound

sound (required)
The audio file you want to play (local or URL).

block (optional, default=True)
Determines whether the sound plays synchronously (blocking) or asynchronously (background).

backend (optional, default=None)
Specify which audio backend to use. If None, the best backend is determined automatically.

To see a list of backends supported by your system:

from playsound3 import AVAILABLE_BACKENDS, DEFAULT_BACKEND

print(AVAILABLE_BACKENDS)  # for example: ["gstreamer", "ffmpeg", ...]
print(DEFAULT_BACKEND)  # for example: "gstreamer"

Sound

playsound returns a Sound object for playback control:

Method Description
.is_alive() Checks if the sound is currently playing.
.wait() Blocks execution until playback finishes.
.stop() Immediately stops playback.

Supported systems

  • Linux
    • GStreamer
    • ALSA (aplay and mpg123)
  • Windows
    • WMPlayer
    • winmm.dll
  • macOS
    • AppKit
    • afplay
  • Multiplatform
    • FFmpeg

Fork information

This repository was originally forked from playsound library created by Taylor Marks. The original library is not maintained anymore and doesn't accept pull requests. This library is a major rewrite of its original.

Feel free to create an issue or contribute to playsound3!

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-3.2.3.tar.gz (607.0 kB view details)

Uploaded Source

Built Distribution

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

playsound3-3.2.3-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: playsound3-3.2.3.tar.gz
  • Upload date:
  • Size: 607.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for playsound3-3.2.3.tar.gz
Algorithm Hash digest
SHA256 248ca0c7690e95d06e04683b9c78cf94c227f7d85a7d2b3558b3fc033f5247a5
MD5 7d753d7c09c8bf7a359ae5b6ed74ee45
BLAKE2b-256 7920d9192ad8331fcf35fd1b184bef95bcedf3d50730b126692359848728ccbd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: playsound3-3.2.3-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for playsound3-3.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 fa1f64ff047aa31add799d982d64c5b72461198f630f87cfa085ae011b4f26bd
MD5 2da29104b21c7d4783f700139be383a1
BLAKE2b-256 71f19f3f40a6f76b214cc5ea6ea7ddd45e0b5c8a3d01fbdc15957a814e22926e

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