On this page
winsound
Prev: winreg | Up: stdlib_module | Next: wsgiref
Rel: os, io, time, argparse, getopt
Ref: docs.python.org — winsound
Tags: #public #python3 #stdlib
Import
import winsound
Overview
Windows-only audio feedback module for playing simple frequency beeps (Beep()), system notification sounds (MessageBeep()), or WAV files (PlaySound()). Use winsound for zero-dependency audio alerts in Windows desktop utilities or long-running scripts.
Quick Start
import sys
if sys.platform == "win32":
import winsound
# Play the standard Windows notification chime
winsound.MessageBeep(winsound.MB_OK)
Implementation Walkthrough
1. Playing a WAV File Asynchronously
Combine SND_FILENAME | SND_ASYNC to start playback without blocking your script (and pass None, SND_PURGE to stop it):
import sys
def notify_done(wav_path: str) -> None:
if sys.platform == "win32":
import winsound
winsound.PlaySound(wav_path, winsound.SND_FILENAME | winsound.SND_ASYNC)
Gotchas & Boundaries
- Windows-only: Unavailable on macOS and Linux (
ModuleNotFoundError). - WAV only for
PlaySound(): Does not decode MP3, OGG, or FLAC;Beep(freq, duration_ms)requiresfreqbetween37and32767Hz. - Blocking by default:
PlaySound()blocks until audio finishes unlessSND_ASYNCis set.
Common Functions
- winsound.Beep() —
Beep(frequency, duration)— Beep the PC's speaker. - winsound.MessageBeep() —
MessageBeep(type=MB_OK)— Call the underlying MessageBeep function from the Platform API. - winsound.PlaySound() —
PlaySound(sound, flags)— Call the underlying PlaySound function from the Platform API.
Linked from
Related notes
- tuts/python3/stdlib_module/stdlib_module Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/winreg Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/winsound/Beep Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/winsound/MessageBeep Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/winsound/PlaySound Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/wsgiref Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/argparse Linked here; shared tags: #stdlib
- tuts/python3/stdlib_module/getopt Linked here; shared tags: #stdlib
- tuts/python3/stdlib_module/io Linked here; shared tags: #stdlib