playsound

repository·master·Indexed 19 days ago

https://github.com/taylorsmarks/playsound

A pure Python, cross-platform, single-function module with no dependencies for playing sounds. Supports local paths and URLs on Windows (via windll.winmm), OS X (via AppKit.NSSound), and Linux (via GStreamer), with options for synchronous or asynchronous playback.

Tokens
466
Snippets
3
Records
4
Agent score
19%

What's inside playsound

  1. Platform support and file formats

    master

    The behavior and supported formats of playsound depend on the host operating system:

    • Windows: Uses windll.winmm. Tested with WAVE and MP3 formats.
    • OS X: Uses AppKit.NSSound. Tested with WAVE and MP3. Generally, any format playable by QuickTime should work.
    • Linux: Uses GStreamer. Known to work on Ubuntu 14.04 and ElementaryOS Loki; typically works on any Linux distribution with a standard GNOME desktop experience.
  2. Quick Start with playsound

    master

    To play a sound file immediately, import the playsound function and pass the path to your audio file (local path or URL) as the first argument.

    from playsound import playsound
    playsound('/path/to/a/sound/file/you/want/to/play.mp3')
  3. Use the playsound function

    master

    The playsound function is the sole entry point of the module. It supports both synchronous (blocking) and asynchronous (non-blocking) playback.

    Arguments:

    • sound (required): The path to the sound file (local file or URL).
    • block (optional): A boolean that defaults to True.
      • If True (default), the function blocks execution until the sound has finished playing.
      • If False, the function runs asynchronously, allowing your script to continue executing while the sound plays.
    from playsound import playsound
    
    # Play synchronously (blocks execution)
    playsound('audio.mp3')
    
    # Play asynchronously (does not block execution)
    playsound('audio.mp3', block=False)