Giter Club home page Giter Club logo

playsound3's Introduction

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, block=True, backend=None) -> 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.
    """
    ...

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)
  • OS X using afplay utility (built-in on OS X)

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
  • is accepting contributions

playsound3's People

Contributors

taylorsmarks avatar sjmikler avatar numerlor avatar akuli avatar antfu avatar hadmanysons avatar jonathangjertsen avatar zedeldi avatar guiweber avatar

Stargazers

Dominik Otrębski avatar EchoQuill avatar Bill Melvin avatar  avatar Manny Fleurmond avatar  avatar

Watchers

 avatar aughhhh avatar

playsound3's Issues

Suggestion to know when the sound is finished

Hello, I was trying to search for ways to reproduce sounds using Python and found the library playsound, and then found out that it was deprecated and you continued the work! Thanks for that.

I tested the module using the block argument, and saw that it doesn't return anything. Wouldn't it be interesting to return some kind of flag in order to know if the sound is still being reproduced? And also being able to stop it as well.

I'm not an expert on developing but I think this feature could be interesting. Would you appreciate a PR to test it out?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.