Debian Codegraph @

Doc/library/winsound.rst

raw
1 :mod:`!winsound` --- Sound-playing interface for Windows
2 ========================================================
3
4 .. module:: winsound
5 :platform: Windows
6 :synopsis: Access to the sound-playing machinery for Windows.
7
8 .. moduleauthor:: Toby Dickenson <[email protected]>
9 .. sectionauthor:: Fred L. Drake, Jr. <[email protected]>
10
11 --------------
12
13 The :mod:`winsound` module provides access to the basic sound-playing machinery
14 provided by Windows platforms. It includes functions and several constants.
15
16 .. availability:: Windows.
17
18
19 .. function:: Beep(frequency, duration)
20
21 Beep the PC's speaker. The *frequency* parameter specifies frequency, in hertz,
22 of the sound, and must be in the range 37 through 32,767. The *duration*
23 parameter specifies the number of milliseconds the sound should last. If the
24 system is not able to beep the speaker, :exc:`RuntimeError` is raised.
25
26
27 .. function:: PlaySound(sound, flags)
28
29 Call the underlying :c:func:`!PlaySound` function from the Platform API. The
30 *sound* parameter may be a filename, a system sound alias, audio data as a
31 :term:`bytes-like object`, or ``None``. Its
32 interpretation depends on the value of *flags*, which can be a bitwise ORed
33 combination of the constants described below. If the *sound* parameter is
34 ``None``, any currently playing waveform sound is stopped. If the system
35 indicates an error, :exc:`RuntimeError` is raised.
36
37
38 .. function:: MessageBeep(type=MB_OK)
39
40 Call the underlying :c:func:`!MessageBeep` function from the Platform API. This
41 plays a sound as specified in the registry. The *type* argument specifies which
42 sound to play; possible values are ``-1``, ``MB_ICONASTERISK``,
43 ``MB_ICONEXCLAMATION``, ``MB_ICONHAND``, ``MB_ICONQUESTION``, and ``MB_OK``, all
44 described below. The value ``-1`` produces a "simple beep"; this is the final
45 fallback if a sound cannot be played otherwise. If the system indicates an
46 error, :exc:`RuntimeError` is raised.
47
48
49 .. data:: SND_FILENAME
50
51 The *sound* parameter is the name of a WAV file. Do not use with
52 :const:`SND_ALIAS`.
53
54
55 .. data:: SND_ALIAS
56
57 The *sound* parameter is a sound association name from the registry. If the
58 registry contains no such name, play the system default sound unless
59 :const:`SND_NODEFAULT` is also specified. If no default sound is registered,
60 raise :exc:`RuntimeError`. Do not use with :const:`SND_FILENAME`.
61
62 All Win32 systems support at least the following; most systems support many
63 more:
64
65 +--------------------------+----------------------------------------+
66 | :func:`PlaySound` *name* | Corresponding Control Panel Sound name |
67 +==========================+========================================+
68 | ``'SystemAsterisk'`` | Asterisk |
69 +--------------------------+----------------------------------------+
70 | ``'SystemExclamation'`` | Exclamation |
71 +--------------------------+----------------------------------------+
72 | ``'SystemExit'`` | Exit Windows |
73 +--------------------------+----------------------------------------+
74 | ``'SystemHand'`` | Critical Stop |
75 +--------------------------+----------------------------------------+
76 | ``'SystemQuestion'`` | Question |
77 +--------------------------+----------------------------------------+
78
79 For example::
80
81 import winsound
82 # Play Windows exit sound.
83 winsound.PlaySound("SystemExit", winsound.SND_ALIAS)
84
85 # Probably play Windows default sound, if any is registered (because
86 # "*" probably isn't the registered name of any sound).
87 winsound.PlaySound("*", winsound.SND_ALIAS)
88
89
90 .. data:: SND_LOOP
91
92 Play the sound repeatedly. The :const:`SND_ASYNC` flag must also be used to
93 avoid blocking. Cannot be used with :const:`SND_MEMORY`.
94
95
96 .. data:: SND_MEMORY
97
98 The *sound* parameter to :func:`PlaySound` is a memory image of a WAV file, as a
99 :term:`bytes-like object`.
100
101 .. note::
102
103 This module does not support playing from a memory image asynchronously, so a
104 combination of this flag and :const:`SND_ASYNC` will raise :exc:`RuntimeError`.
105
106
107 .. data:: SND_PURGE
108
109 Stop playing all instances of the specified sound.
110
111 .. note::
112
113 This flag is not supported on modern Windows platforms.
114
115
116 .. data:: SND_ASYNC
117
118 Return immediately, allowing sounds to play asynchronously.
119
120
121 .. data:: SND_NODEFAULT
122
123 If the specified sound cannot be found, do not play the system default sound.
124
125
126 .. data:: SND_NOSTOP
127
128 Do not interrupt sounds currently playing.
129
130
131 .. data:: SND_NOWAIT
132
133 Return immediately if the sound driver is busy.
134
135 .. note::
136
137 This flag is not supported on modern Windows platforms.
138
139
140 .. data:: SND_APPLICATION
141
142 The *sound* parameter is an application-specific alias in the registry.
143 This flag can be combined with the :const:`SND_ALIAS` flag
144 to specify an application-defined sound alias.
145
146
147 .. data:: MB_ICONASTERISK
148
149 Play the ``SystemDefault`` sound.
150
151
152 .. data:: MB_ICONEXCLAMATION
153
154 Play the ``SystemExclamation`` sound.
155
156
157 .. data:: MB_ICONHAND
158
159 Play the ``SystemHand`` sound.
160
161
162 .. data:: MB_ICONQUESTION
163
164 Play the ``SystemQuestion`` sound.
165
166
167 .. data:: MB_OK
168
169 Play the ``SystemDefault`` sound.
170