<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8" /> <title>winsound — Sound-playing interface for Windows — Python 3.7.4 documentation</title> <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/language_data.js"></script> <script type="text/javascript" src="../_static/sidebar.js"></script> <link rel="search" type="application/opensearchdescription+xml" title="Search within Python 3.7.4 documentation" href="../_static/opensearch.xml"/> <link rel="author" title="About these documents" href="../about.html" /> <link rel="index" title="Index" href="../genindex.html" /> <link rel="search" title="Search" href="../search.html" /> <link rel="copyright" title="Copyright" href="../copyright.html" /> <link rel="next" title="Unix Specific Services" href="unix.html" /> <link rel="prev" title="winreg — Windows registry access" href="winreg.html" /> <link rel="shortcut icon" type="image/png" href="../_static/py.png" /> <link rel="canonical" href="https://docs.python.org/3/library/winsound.html" /> <script type="text/javascript" src="../_static/copybutton.js"></script> <script type="text/javascript" src="../_static/switchers.js"></script> <style> @media only screen { table.full-width-table { width: 100%; } } </style> </head><body> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="unix.html" title="Unix Specific Services" accesskey="N">next</a> |</li> <li class="right" > <a href="winreg.html" title="winreg — Windows registry access" accesskey="P">previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="https://www.python.org/">Python</a> »</li> <li> <span class="language_switcher_placeholder">en</span> <span class="version_switcher_placeholder">3.7.4</span> <a href="../index.html">Documentation </a> » </li> <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li> <li class="nav-item nav-item-2"><a href="windows.html" accesskey="U">MS Windows Specific Services</a> »</li> <li class="right"> <div class="inline-search" style="display: none" role="search"> <form class="inline-search" action="../search.html" method="get"> <input placeholder="Quick search" type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </div> <script type="text/javascript">$('.inline-search').show(0);</script> | </li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <div class="section" id="module-winsound"> <span id="winsound-sound-playing-interface-for-windows"></span><h1><a class="reference internal" href="#module-winsound" title="winsound: Access to the sound-playing machinery for Windows. (Windows)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">winsound</span></code></a> — Sound-playing interface for Windows<a class="headerlink" href="#module-winsound" title="Permalink to this headline">¶</a></h1> <hr class="docutils" /> <p>The <a class="reference internal" href="#module-winsound" title="winsound: Access to the sound-playing machinery for Windows. (Windows)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">winsound</span></code></a> module provides access to the basic sound-playing machinery provided by Windows platforms. It includes functions and several constants.</p> <dl class="function"> <dt id="winsound.Beep"> <code class="descclassname">winsound.</code><code class="descname">Beep</code><span class="sig-paren">(</span><em>frequency</em>, <em>duration</em><span class="sig-paren">)</span><a class="headerlink" href="#winsound.Beep" title="Permalink to this definition">¶</a></dt> <dd><p>Beep the PC’s speaker. The <em>frequency</em> parameter specifies frequency, in hertz, of the sound, and must be in the range 37 through 32,767. The <em>duration</em> parameter specifies the number of milliseconds the sound should last. If the system is not able to beep the speaker, <a class="reference internal" href="exceptions.html#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a> is raised.</p> </dd></dl> <dl class="function"> <dt id="winsound.PlaySound"> <code class="descclassname">winsound.</code><code class="descname">PlaySound</code><span class="sig-paren">(</span><em>sound</em>, <em>flags</em><span class="sig-paren">)</span><a class="headerlink" href="#winsound.PlaySound" title="Permalink to this definition">¶</a></dt> <dd><p>Call the underlying <code class="xref c c-func docutils literal notranslate"><span class="pre">PlaySound()</span></code> function from the Platform API. The <em>sound</em> parameter may be a filename, a system sound alias, audio data as a <a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">bytes-like object</span></a>, or <code class="docutils literal notranslate"><span class="pre">None</span></code>. Its interpretation depends on the value of <em>flags</em>, which can be a bitwise ORed combination of the constants described below. If the <em>sound</em> parameter is <code class="docutils literal notranslate"><span class="pre">None</span></code>, any currently playing waveform sound is stopped. If the system indicates an error, <a class="reference internal" href="exceptions.html#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a> is raised.</p> </dd></dl> <dl class="function"> <dt id="winsound.MessageBeep"> <code class="descclassname">winsound.</code><code class="descname">MessageBeep</code><span class="sig-paren">(</span><em>type=MB_OK</em><span class="sig-paren">)</span><a class="headerlink" href="#winsound.MessageBeep" title="Permalink to this definition">¶</a></dt> <dd><p>Call the underlying <code class="xref c c-func docutils literal notranslate"><span class="pre">MessageBeep()</span></code> function from the Platform API. This plays a sound as specified in the registry. The <em>type</em> argument specifies which sound to play; possible values are <code class="docutils literal notranslate"><span class="pre">-1</span></code>, <code class="docutils literal notranslate"><span class="pre">MB_ICONASTERISK</span></code>, <code class="docutils literal notranslate"><span class="pre">MB_ICONEXCLAMATION</span></code>, <code class="docutils literal notranslate"><span class="pre">MB_ICONHAND</span></code>, <code class="docutils literal notranslate"><span class="pre">MB_ICONQUESTION</span></code>, and <code class="docutils literal notranslate"><span class="pre">MB_OK</span></code>, all described below. The value <code class="docutils literal notranslate"><span class="pre">-1</span></code> produces a “simple beep”; this is the final fallback if a sound cannot be played otherwise. If the system indicates an error, <a class="reference internal" href="exceptions.html#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a> is raised.</p> </dd></dl> <dl class="data"> <dt id="winsound.SND_FILENAME"> <code class="descclassname">winsound.</code><code class="descname">SND_FILENAME</code><a class="headerlink" href="#winsound.SND_FILENAME" title="Permalink to this definition">¶</a></dt> <dd><p>The <em>sound</em> parameter is the name of a WAV file. Do not use with <a class="reference internal" href="#winsound.SND_ALIAS" title="winsound.SND_ALIAS"><code class="xref py py-const docutils literal notranslate"><span class="pre">SND_ALIAS</span></code></a>.</p> </dd></dl> <dl class="data"> <dt id="winsound.SND_ALIAS"> <code class="descclassname">winsound.</code><code class="descname">SND_ALIAS</code><a class="headerlink" href="#winsound.SND_ALIAS" title="Permalink to this definition">¶</a></dt> <dd><p>The <em>sound</em> parameter is a sound association name from the registry. If the registry contains no such name, play the system default sound unless <a class="reference internal" href="#winsound.SND_NODEFAULT" title="winsound.SND_NODEFAULT"><code class="xref py py-const docutils literal notranslate"><span class="pre">SND_NODEFAULT</span></code></a> is also specified. If no default sound is registered, raise <a class="reference internal" href="exceptions.html#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a>. Do not use with <a class="reference internal" href="#winsound.SND_FILENAME" title="winsound.SND_FILENAME"><code class="xref py py-const docutils literal notranslate"><span class="pre">SND_FILENAME</span></code></a>.</p> <p>All Win32 systems support at least the following; most systems support many more:</p> <table class="docutils align-center"> <colgroup> <col style="width: 39%" /> <col style="width: 61%" /> </colgroup> <thead> <tr class="row-odd"><th class="head"><p><a class="reference internal" href="#winsound.PlaySound" title="winsound.PlaySound"><code class="xref py py-func docutils literal notranslate"><span class="pre">PlaySound()</span></code></a> <em>name</em></p></th> <th class="head"><p>Corresponding Control Panel Sound name</p></th> </tr> </thead> <tbody> <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">'SystemAsterisk'</span></code></p></td> <td><p>Asterisk</p></td> </tr> <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">'SystemExclamation'</span></code></p></td> <td><p>Exclamation</p></td> </tr> <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">'SystemExit'</span></code></p></td> <td><p>Exit Windows</p></td> </tr> <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">'SystemHand'</span></code></p></td> <td><p>Critical Stop</p></td> </tr> <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">'SystemQuestion'</span></code></p></td> <td><p>Question</p></td> </tr> </tbody> </table> <p>For example:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">winsound</span> <span class="c1"># Play Windows exit sound.</span> <span class="n">winsound</span><span class="o">.</span><span class="n">PlaySound</span><span class="p">(</span><span class="s2">"SystemExit"</span><span class="p">,</span> <span class="n">winsound</span><span class="o">.</span><span class="n">SND_ALIAS</span><span class="p">)</span> <span class="c1"># Probably play Windows default sound, if any is registered (because</span> <span class="c1"># "*" probably isn't the registered name of any sound).</span> <span class="n">winsound</span><span class="o">.</span><span class="n">PlaySound</span><span class="p">(</span><span class="s2">"*"</span><span class="p">,</span> <span class="n">winsound</span><span class="o">.</span><span class="n">SND_ALIAS</span><span class="p">)</span> </pre></div> </div> </dd></dl> <dl class="data"> <dt id="winsound.SND_LOOP"> <code class="descclassname">winsound.</code><code class="descname">SND_LOOP</code><a class="headerlink" href="#winsound.SND_LOOP" title="Permalink to this definition">¶</a></dt> <dd><p>Play the sound repeatedly. The <a class="reference internal" href="#winsound.SND_ASYNC" title="winsound.SND_ASYNC"><code class="xref py py-const docutils literal notranslate"><span class="pre">SND_ASYNC</span></code></a> flag must also be used to avoid blocking. Cannot be used with <a class="reference internal" href="#winsound.SND_MEMORY" title="winsound.SND_MEMORY"><code class="xref py py-const docutils literal notranslate"><span class="pre">SND_MEMORY</span></code></a>.</p> </dd></dl> <dl class="data"> <dt id="winsound.SND_MEMORY"> <code class="descclassname">winsound.</code><code class="descname">SND_MEMORY</code><a class="headerlink" href="#winsound.SND_MEMORY" title="Permalink to this definition">¶</a></dt> <dd><p>The <em>sound</em> parameter to <a class="reference internal" href="#winsound.PlaySound" title="winsound.PlaySound"><code class="xref py py-func docutils literal notranslate"><span class="pre">PlaySound()</span></code></a> is a memory image of a WAV file, as a <a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">bytes-like object</span></a>.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p>This module does not support playing from a memory image asynchronously, so a combination of this flag and <a class="reference internal" href="#winsound.SND_ASYNC" title="winsound.SND_ASYNC"><code class="xref py py-const docutils literal notranslate"><span class="pre">SND_ASYNC</span></code></a> will raise <a class="reference internal" href="exceptions.html#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a>.</p> </div> </dd></dl> <dl class="data"> <dt id="winsound.SND_PURGE"> <code class="descclassname">winsound.</code><code class="descname">SND_PURGE</code><a class="headerlink" href="#winsound.SND_PURGE" title="Permalink to this definition">¶</a></dt> <dd><p>Stop playing all instances of the specified sound.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p>This flag is not supported on modern Windows platforms.</p> </div> </dd></dl> <dl class="data"> <dt id="winsound.SND_ASYNC"> <code class="descclassname">winsound.</code><code class="descname">SND_ASYNC</code><a class="headerlink" href="#winsound.SND_ASYNC" title="Permalink to this definition">¶</a></dt> <dd><p>Return immediately, allowing sounds to play asynchronously.</p> </dd></dl> <dl class="data"> <dt id="winsound.SND_NODEFAULT"> <code class="descclassname">winsound.</code><code class="descname">SND_NODEFAULT</code><a class="headerlink" href="#winsound.SND_NODEFAULT" title="Permalink to this definition">¶</a></dt> <dd><p>If the specified sound cannot be found, do not play the system default sound.</p> </dd></dl> <dl class="data"> <dt id="winsound.SND_NOSTOP"> <code class="descclassname">winsound.</code><code class="descname">SND_NOSTOP</code><a class="headerlink" href="#winsound.SND_NOSTOP" title="Permalink to this definition">¶</a></dt> <dd><p>Do not interrupt sounds currently playing.</p> </dd></dl> <dl class="data"> <dt id="winsound.SND_NOWAIT"> <code class="descclassname">winsound.</code><code class="descname">SND_NOWAIT</code><a class="headerlink" href="#winsound.SND_NOWAIT" title="Permalink to this definition">¶</a></dt> <dd><p>Return immediately if the sound driver is busy.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p>This flag is not supported on modern Windows platforms.</p> </div> </dd></dl> <dl class="data"> <dt id="winsound.MB_ICONASTERISK"> <code class="descclassname">winsound.</code><code class="descname">MB_ICONASTERISK</code><a class="headerlink" href="#winsound.MB_ICONASTERISK" title="Permalink to this definition">¶</a></dt> <dd><p>Play the <code class="docutils literal notranslate"><span class="pre">SystemDefault</span></code> sound.</p> </dd></dl> <dl class="data"> <dt id="winsound.MB_ICONEXCLAMATION"> <code class="descclassname">winsound.</code><code class="descname">MB_ICONEXCLAMATION</code><a class="headerlink" href="#winsound.MB_ICONEXCLAMATION" title="Permalink to this definition">¶</a></dt> <dd><p>Play the <code class="docutils literal notranslate"><span class="pre">SystemExclamation</span></code> sound.</p> </dd></dl> <dl class="data"> <dt id="winsound.MB_ICONHAND"> <code class="descclassname">winsound.</code><code class="descname">MB_ICONHAND</code><a class="headerlink" href="#winsound.MB_ICONHAND" title="Permalink to this definition">¶</a></dt> <dd><p>Play the <code class="docutils literal notranslate"><span class="pre">SystemHand</span></code> sound.</p> </dd></dl> <dl class="data"> <dt id="winsound.MB_ICONQUESTION"> <code class="descclassname">winsound.</code><code class="descname">MB_ICONQUESTION</code><a class="headerlink" href="#winsound.MB_ICONQUESTION" title="Permalink to this definition">¶</a></dt> <dd><p>Play the <code class="docutils literal notranslate"><span class="pre">SystemQuestion</span></code> sound.</p> </dd></dl> <dl class="data"> <dt id="winsound.MB_OK"> <code class="descclassname">winsound.</code><code class="descname">MB_OK</code><a class="headerlink" href="#winsound.MB_OK" title="Permalink to this definition">¶</a></dt> <dd><p>Play the <code class="docutils literal notranslate"><span class="pre">SystemDefault</span></code> sound.</p> </dd></dl> </div> </div> </div> </div> <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> <div class="sphinxsidebarwrapper"> <h4>Previous topic</h4> <p class="topless"><a href="winreg.html" title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">winreg</span></code> — Windows registry access</a></p> <h4>Next topic</h4> <p class="topless"><a href="unix.html" title="next chapter">Unix Specific Services</a></p> <div role="note" aria-label="source link"> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../bugs.html">Report a Bug</a></li> <li> <a href="https://github.com/python/cpython/blob/3.7/Doc/library/winsound.rst" rel="nofollow">Show Source </a> </li> </ul> </div> </div> </div> <div class="clearer"></div> </div> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="unix.html" title="Unix Specific Services" >next</a> |</li> <li class="right" > <a href="winreg.html" title="winreg — Windows registry access" >previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="https://www.python.org/">Python</a> »</li> <li> <span class="language_switcher_placeholder">en</span> <span class="version_switcher_placeholder">3.7.4</span> <a href="../index.html">Documentation </a> » </li> <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li> <li class="nav-item nav-item-2"><a href="windows.html" >MS Windows Specific Services</a> »</li> <li class="right"> <div class="inline-search" style="display: none" role="search"> <form class="inline-search" action="../search.html" method="get"> <input placeholder="Quick search" type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </div> <script type="text/javascript">$('.inline-search').show(0);</script> | </li> </ul> </div> <div class="footer"> © <a href="../copyright.html">Copyright</a> 2001-2019, Python Software Foundation. <br /> The Python Software Foundation is a non-profit corporation. <a href="https://www.python.org/psf/donations/">Please donate.</a> <br /> Last updated on Jul 13, 2019. <a href="../bugs.html">Found a bug</a>? <br /> Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 2.0.1. </div> </body> </html>