| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> |
| 5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> |
| 6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> |
| 7 | <link rel="first" href="lib.html" title='Python Library Reference' /> |
| 8 | <link rel='contents' href='contents.html' title="Contents" /> |
| 9 | <link rel='index' href='genindex.html' title='Index' /> |
| 10 | <link rel='last' href='about.html' title='About this document...' /> |
| 11 | <link rel='help' href='about.html' title='About this document...' /> |
| 12 | <link rel="prev" href="module--winreg.html" /> |
| 13 | <link rel="parent" href="node822.html" /> |
| 14 | <link rel="next" href="undoc.html" /> |
| 15 | <meta name='aesop' content='information' /> |
| 16 | <title>22.3 winsound -- Sound-playing interface for Windows</title> |
| 17 | </head> |
| 18 | <body> |
| 19 | <DIV CLASS="navigation"> |
| 20 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> |
| 21 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 22 | <tr> |
| 23 | <td class='online-navigation'><a rel="prev" title="22.2.1 Registry Handle Objects" |
| 24 | href="handle-object.html"><img src='../icons/previous.png' |
| 25 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 26 | <td class='online-navigation'><a rel="parent" title="22. MS Windows Specific" |
| 27 | href="node822.html"><img src='../icons/up.png' |
| 28 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 29 | <td class='online-navigation'><a rel="next" title="A. Undocumented Modules" |
| 30 | href="undoc.html"><img src='../icons/next.png' |
| 31 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 32 | <td align="center" width="100%">Python Library Reference</td> |
| 33 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 34 | href="contents.html"><img src='../icons/contents.png' |
| 35 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 36 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 37 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 38 | <td class='online-navigation'><a rel="index" title="Index" |
| 39 | href="genindex.html"><img src='../icons/index.png' |
| 40 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 41 | </tr></table> |
| 42 | <div class='online-navigation'> |
| 43 | <b class="navlabel">Previous:</b> |
| 44 | <a class="sectref" rel="prev" href="handle-object.html">22.2.1 Registry Handle Objects</A> |
| 45 | <b class="navlabel">Up:</b> |
| 46 | <a class="sectref" rel="parent" href="node822.html">22. MS Windows Specific</A> |
| 47 | <b class="navlabel">Next:</b> |
| 48 | <a class="sectref" rel="next" href="undoc.html">A. Undocumented Modules</A> |
| 49 | </div> |
| 50 | <hr /></div> |
| 51 | </DIV> |
| 52 | <!--End of Navigation Panel--> |
| 53 | |
| 54 | <H1><A NAME="SECTION0024300000000000000000"> |
| 55 | 22.3 <tt class="module">winsound</tt> -- |
| 56 | Sound-playing interface for Windows</A> |
| 57 | </H1> |
| 58 | |
| 59 | <P> |
| 60 | <A NAME="module-winsound"></A> |
| 61 | <p class="availability">Availability: <span |
| 62 | class="platform">Windows</span>.</p> |
| 63 | |
| 64 | <P> |
| 65 | |
| 66 | <span class="versionnote">New in version 1.5.2.</span> |
| 67 | |
| 68 | <P> |
| 69 | The <tt class="module">winsound</tt> module provides access to the basic |
| 70 | sound-playing machinery provided by Windows platforms. It includes |
| 71 | functions and several constants. |
| 72 | |
| 73 | <P> |
| 74 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 75 | <td><nobr><b><tt id='l2h-5276' xml:id='l2h-5276' class="function">Beep</tt></b>(</nobr></td> |
| 76 | <td><var>frequency, duration</var>)</td></tr></table></dt> |
| 77 | <dd> |
| 78 | Beep the PC's speaker. |
| 79 | The <var>frequency</var> parameter specifies frequency, in hertz, of the |
| 80 | sound, and must be in the range 37 through 32,767. |
| 81 | The <var>duration</var> parameter specifies the number of milliseconds the |
| 82 | sound should last. If the system is not |
| 83 | able to beep the speaker, <tt class="exception">RuntimeError</tt> is raised. |
| 84 | <span class="note"><b class="label">Note:</b> |
| 85 | Under Windows 95 and 98, the Windows <tt class="cfunction">Beep()</tt> |
| 86 | function exists but is useless (it ignores its arguments). In that |
| 87 | case Python simulates it via direct port manipulation (added in version |
| 88 | 2.1). It's unknown whether that will work on all systems.</span> |
| 89 | |
| 90 | <span class="versionnote">New in version 1.6.</span> |
| 91 | |
| 92 | </dl> |
| 93 | |
| 94 | <P> |
| 95 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 96 | <td><nobr><b><tt id='l2h-5277' xml:id='l2h-5277' class="function">PlaySound</tt></b>(</nobr></td> |
| 97 | <td><var>sound, flags</var>)</td></tr></table></dt> |
| 98 | <dd> |
| 99 | Call the underlying <tt class="cfunction">PlaySound()</tt> function from the |
| 100 | Platform API. The <var>sound</var> parameter may be a filename, audio |
| 101 | data as a string, or <code>None</code>. Its interpretation depends on the |
| 102 | value of <var>flags</var>, which can be a bit-wise ORed combination of |
| 103 | the constants described below. If the system indicates an error, |
| 104 | <tt class="exception">RuntimeError</tt> is raised. |
| 105 | </dl> |
| 106 | |
| 107 | <P> |
| 108 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 109 | <td><nobr><b><tt id='l2h-5278' xml:id='l2h-5278' class="function">MessageBeep</tt></b>(</nobr></td> |
| 110 | <td><var></var><big>[</big><var>type=<code>MB_OK</code></var><big>]</big><var></var>)</td></tr></table></dt> |
| 111 | <dd> |
| 112 | Call the underlying <tt class="cfunction">MessageBeep()</tt> function from the |
| 113 | Platform API. This plays a sound as specified in the registry. The |
| 114 | <var>type</var> argument specifies which sound to play; possible values |
| 115 | are <code>-1</code>, <code>MB_ICONASTERISK</code>, <code>MB_ICONEXCLAMATION</code>, |
| 116 | <code>MB_ICONHAND</code>, <code>MB_ICONQUESTION</code>, and <code>MB_OK</code>, all |
| 117 | described below. The value <code>-1</code> produces a ``simple beep''; |
| 118 | this is the final fallback if a sound cannot be played otherwise. |
| 119 | |
| 120 | <span class="versionnote">New in version 2.3.</span> |
| 121 | |
| 122 | </dl> |
| 123 | |
| 124 | <P> |
| 125 | <dl><dt><b><tt id='l2h-5279' xml:id='l2h-5279'>SND_FILENAME</tt></b></dt> |
| 126 | <dd> |
| 127 | The <var>sound</var> parameter is the name of a WAV file. |
| 128 | Do not use with <tt class="constant">SND_ALIAS</tt>. |
| 129 | </dd></dl> |
| 130 | |
| 131 | <P> |
| 132 | <dl><dt><b><tt id='l2h-5280' xml:id='l2h-5280'>SND_ALIAS</tt></b></dt> |
| 133 | <dd> |
| 134 | The <var>sound</var> parameter is a sound association name from the |
| 135 | registry. If the registry contains no such name, play the system |
| 136 | default sound unless <tt class="constant">SND_NODEFAULT</tt> is also specified. |
| 137 | If no default sound is registered, raise <tt class="exception">RuntimeError</tt>. |
| 138 | Do not use with <tt class="constant">SND_FILENAME</tt>. |
| 139 | |
| 140 | <P> |
| 141 | All Win32 systems support at least the following; most systems support |
| 142 | many more: |
| 143 | |
| 144 | <P> |
| 145 | <div class="center"><table class="realtable"> |
| 146 | <thead> |
| 147 | <tr> |
| 148 | <th class="left" ><tt class="function">PlaySound()</tt> <var>name</var></th> |
| 149 | <th class="left" >Corresponding Control Panel Sound name</th> |
| 150 | </tr> |
| 151 | </thead> |
| 152 | <tbody> |
| 153 | <tr><td class="left" valign="baseline"><code>'SystemAsterisk'</code></td> |
| 154 | <td class="left" >Asterisk</td></tr> |
| 155 | <tr><td class="left" valign="baseline"><code>'SystemExclamation'</code></td> |
| 156 | <td class="left" >Exclamation</td></tr> |
| 157 | <tr><td class="left" valign="baseline"><code>'SystemExit'</code></td> |
| 158 | <td class="left" >Exit Windows</td></tr> |
| 159 | <tr><td class="left" valign="baseline"><code>'SystemHand'</code></td> |
| 160 | <td class="left" >Critical Stop</td></tr> |
| 161 | <tr><td class="left" valign="baseline"><code>'SystemQuestion'</code></td> |
| 162 | <td class="left" >Question</td></tr></tbody> |
| 163 | </table></div> |
| 164 | |
| 165 | <P> |
| 166 | For example: |
| 167 | |
| 168 | <P> |
| 169 | <div class="verbatim"><pre> |
| 170 | import winsound |
| 171 | # Play Windows exit sound. |
| 172 | winsound.PlaySound("SystemExit", winsound.SND_ALIAS) |
| 173 | |
| 174 | # Probably play Windows default sound, if any is registered (because |
| 175 | # "*" probably isn't the registered name of any sound). |
| 176 | winsound.PlaySound("*", winsound.SND_ALIAS) |
| 177 | </pre></div> |
| 178 | </dd></dl> |
| 179 | |
| 180 | <P> |
| 181 | <dl><dt><b><tt id='l2h-5281' xml:id='l2h-5281'>SND_LOOP</tt></b></dt> |
| 182 | <dd> |
| 183 | Play the sound repeatedly. The <tt class="constant">SND_ASYNC</tt> flag must also |
| 184 | be used to avoid blocking. Cannot be used with <tt class="constant">SND_MEMORY</tt>. |
| 185 | </dd></dl> |
| 186 | |
| 187 | <P> |
| 188 | <dl><dt><b><tt id='l2h-5282' xml:id='l2h-5282'>SND_MEMORY</tt></b></dt> |
| 189 | <dd> |
| 190 | The <var>sound</var> parameter to <tt class="function">PlaySound()</tt> is a memory |
| 191 | image of a WAV file, as a string. |
| 192 | |
| 193 | <P> |
| 194 | <span class="note"><b class="label">Note:</b> |
| 195 | This module does not support playing from a memory |
| 196 | image asynchronously, so a combination of this flag and |
| 197 | <tt class="constant">SND_ASYNC</tt> will raise <tt class="exception">RuntimeError</tt>.</span> |
| 198 | </dd></dl> |
| 199 | |
| 200 | <P> |
| 201 | <dl><dt><b><tt id='l2h-5283' xml:id='l2h-5283'>SND_PURGE</tt></b></dt> |
| 202 | <dd> |
| 203 | Stop playing all instances of the specified sound. |
| 204 | </dd></dl> |
| 205 | |
| 206 | <P> |
| 207 | <dl><dt><b><tt id='l2h-5284' xml:id='l2h-5284'>SND_ASYNC</tt></b></dt> |
| 208 | <dd> |
| 209 | Return immediately, allowing sounds to play asynchronously. |
| 210 | </dd></dl> |
| 211 | |
| 212 | <P> |
| 213 | <dl><dt><b><tt id='l2h-5285' xml:id='l2h-5285'>SND_NODEFAULT</tt></b></dt> |
| 214 | <dd> |
| 215 | If the specified sound cannot be found, do not play the system default |
| 216 | sound. |
| 217 | </dd></dl> |
| 218 | |
| 219 | <P> |
| 220 | <dl><dt><b><tt id='l2h-5286' xml:id='l2h-5286'>SND_NOSTOP</tt></b></dt> |
| 221 | <dd> |
| 222 | Do not interrupt sounds currently playing. |
| 223 | </dd></dl> |
| 224 | |
| 225 | <P> |
| 226 | <dl><dt><b><tt id='l2h-5287' xml:id='l2h-5287'>SND_NOWAIT</tt></b></dt> |
| 227 | <dd> |
| 228 | Return immediately if the sound driver is busy. |
| 229 | </dd></dl> |
| 230 | |
| 231 | <P> |
| 232 | <dl><dt><b><tt id='l2h-5288' xml:id='l2h-5288'>MB_ICONASTERISK</tt></b></dt> |
| 233 | <dd> |
| 234 | Play the <code>SystemDefault</code> sound. |
| 235 | </dd></dl> |
| 236 | |
| 237 | <P> |
| 238 | <dl><dt><b><tt id='l2h-5289' xml:id='l2h-5289'>MB_ICONEXCLAMATION</tt></b></dt> |
| 239 | <dd> |
| 240 | Play the <code>SystemExclamation</code> sound. |
| 241 | </dd></dl> |
| 242 | |
| 243 | <P> |
| 244 | <dl><dt><b><tt id='l2h-5290' xml:id='l2h-5290'>MB_ICONHAND</tt></b></dt> |
| 245 | <dd> |
| 246 | Play the <code>SystemHand</code> sound. |
| 247 | </dd></dl> |
| 248 | |
| 249 | <P> |
| 250 | <dl><dt><b><tt id='l2h-5291' xml:id='l2h-5291'>MB_ICONQUESTION</tt></b></dt> |
| 251 | <dd> |
| 252 | Play the <code>SystemQuestion</code> sound. |
| 253 | </dd></dl> |
| 254 | |
| 255 | <P> |
| 256 | <dl><dt><b><tt id='l2h-5292' xml:id='l2h-5292'>MB_OK</tt></b></dt> |
| 257 | <dd> |
| 258 | Play the <code>SystemDefault</code> sound. |
| 259 | </dd></dl> |
| 260 | |
| 261 | <P> |
| 262 | |
| 263 | |
| 264 | <DIV CLASS="navigation"> |
| 265 | <div class='online-navigation'> |
| 266 | <p></p><hr /> |
| 267 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 268 | <tr> |
| 269 | <td class='online-navigation'><a rel="prev" title="22.2.1 Registry Handle Objects" |
| 270 | href="handle-object.html"><img src='../icons/previous.png' |
| 271 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 272 | <td class='online-navigation'><a rel="parent" title="22. MS Windows Specific" |
| 273 | href="node822.html"><img src='../icons/up.png' |
| 274 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 275 | <td class='online-navigation'><a rel="next" title="A. Undocumented Modules" |
| 276 | href="undoc.html"><img src='../icons/next.png' |
| 277 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 278 | <td align="center" width="100%">Python Library Reference</td> |
| 279 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 280 | href="contents.html"><img src='../icons/contents.png' |
| 281 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 282 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 283 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 284 | <td class='online-navigation'><a rel="index" title="Index" |
| 285 | href="genindex.html"><img src='../icons/index.png' |
| 286 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 287 | </tr></table> |
| 288 | <div class='online-navigation'> |
| 289 | <b class="navlabel">Previous:</b> |
| 290 | <a class="sectref" rel="prev" href="handle-object.html">22.2.1 Registry Handle Objects</A> |
| 291 | <b class="navlabel">Up:</b> |
| 292 | <a class="sectref" rel="parent" href="node822.html">22. MS Windows Specific</A> |
| 293 | <b class="navlabel">Next:</b> |
| 294 | <a class="sectref" rel="next" href="undoc.html">A. Undocumented Modules</A> |
| 295 | </div> |
| 296 | </div> |
| 297 | <hr /> |
| 298 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> |
| 299 | </DIV> |
| 300 | <!--End of Navigation Panel--> |
| 301 | <ADDRESS> |
| 302 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. |
| 303 | </ADDRESS> |
| 304 | </BODY> |
| 305 | </HTML> |