{"library":"playsound","title":"playsound","description":"playsound is a pure Python, cross-platform module designed for playing sounds with a single function call. It aims for simplicity and has no external Python dependencies. The current version is 1.3.0, released in 2021, indicating a stable but currently dormant release cadence.","language":"python","status":"maintenance","last_verified":"Fri Apr 17","install":{"commands":["pip install playsound"],"cli":null},"imports":["from playsound import playsound"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nimport tempfile\nfrom playsound import playsound\n\n# Create a dummy WAV file for demonstration\n# (playsound has no stop/pause, so a very short sound is ideal)\n# In a real scenario, use an actual sound file like 'path/to/my_sound.wav'\n# NOTE: For Windows, WAV is the most reliable format. MP3 support is limited.\n\ntry:\n    with tempfile.NamedTemporaryFile(suffix=\".wav\", delete=False) as tmp_file:\n        tmp_file_name = tmp_file.name\n        # Minimal WAV header + 1 second of silent audio for demonstration\n        # This is a very basic valid WAV header for a mono 16-bit 44.1kHz sound\n        wav_header = b'RIFF\\x2c\\x00\\x00\\x00WAVEfmt \\x10\\x00\\x00\\x00\\x01\\x00\\x01\\x00D\\xac\\x00\\x00\\x88\\x58\\x01\\x00\\x02\\x00\\x10\\x00data\\x08\\x00\\x00\\x00\\x00\\x00\\x00\\x00'\n        tmp_file.write(wav_header)\n        tmp_file.flush()\n\n    print(f\"Playing sound from: {tmp_file_name}\")\n    playsound(tmp_file_name)\n    print(\"Sound playback finished.\")\n\nfinally:\n    if 'tmp_file_name' in locals() and os.path.exists(tmp_file_name):\n        os.remove(tmp_file_name)\n        print(f\"Cleaned up temporary file: {tmp_file_name}\")\n","lang":"python","description":"This example demonstrates how to play a sound file using `playsound`. It dynamically creates a small, silent WAV file for cross-platform compatibility and then plays it. Replace `tmp_file_name` with the actual path to your sound file (e.g., `playsound('path/to/your/audio.mp3')`). Be aware that `playsound` blocks the execution of the script until the sound finishes, and specific audio formats may have platform-dependent support.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}