<p>I'd like to have a python program alert me when it has completed its task by making a beep noise.  Currently,  I use <code>import os</code> and then use a command line speech program to say &quot;Process complete&quot;.  I much rather it be a simple &quot;bell.&quot;</p>
<p>I know that there's a function that can be used in <em>Cocoa</em> apps, <code>NSBeep</code>, but I don't think that has much anything to do with this.</p>
<p>I've also tried</p>
<pre class="lang-py prettyprint-override"><code>print(\a)
</code></pre>
<p>but that didn't work.</p>
<p>I'm using a Mac, if you couldn't tell by my <em>Cocoa</em> comment, so that may help.</p>

[{'answer_id': 13949, 'author': 'gbc', 'author_id': 1667, 'author_profile': 'https://Stackoverflow.com/users/1667', 'pm_score': 7, 'selected': True, 'text': "<p>Have you tried :</p>\n\n<pre><code>import sys\nsys.stdout.write('\\a')\nsys.stdout.flush()\n</code></pre>\n\n<p>That works for me here on Mac OS 10.5</p>\n\n<p>Actually, I think your original attempt works also with a little modification:</p>\n\n<pre><code>print('\\a')\n</code></pre>\n\n<p>(You just need the single quotes around the character sequence).</p>\n"}, {'answer_id': 13959, 'author': 'markpasc', 'author_id': 1472, 'author_profile': 'https://Stackoverflow.com/users/1472', 'pm_score': 3, 'selected': False, 'text': '<p>I had to turn off the "Silence terminal bell" option in my active Terminal Profile in iTerm for <code>print(\'\\a\')</code> to work. It seemed to work fine by default in Terminal.</p>\n\n<p>You can also use the Mac module <code>Carbon.Snd</code> to play the system beep:</p>\n\n<pre><code>&gt;&gt;&gt; import Carbon.Snd\n&gt;&gt;&gt; Carbon.Snd.SysBeep(1)\n&gt;&gt;&gt; \n</code></pre>\n\n<p>The Carbon modules don\'t have any documentation, so I had to use <code>help(Carbon.Snd)</code> to see what functions were available. It seems to be a direct interface onto Carbon, so the docs on Apple Developer Connection probably help.</p>\n'}, {'answer_id': 34482, 'author': 'Barry Wark', 'author_id': 2140, 'author_profile': 'https://Stackoverflow.com/users/2140', 'pm_score': 4, 'selected': False, 'text': "<p>If you have PyObjC (the Python - Objective-C bridge) installed or are running on OS X 10.5's system python (which ships with PyObjC), you can do</p>\n\n<pre><code>from AppKit import NSBeep\nNSBeep()\n</code></pre>\n\n<p>to play the system alert.</p>\n"}, {'answer_id': 6110229, 'author': 'Abhranil Das', 'author_id': 711017, 'author_profile': 'https://Stackoverflow.com/users/711017', 'pm_score': 3, 'selected': False, 'text': "<p>I tried the mixer from the pygame module, and it works fine. First install the module:</p>\n\n<pre><code>$ sudo apt-get install python-pygame\n</code></pre>\n\n<p>Then in the program, write this:</p>\n\n<pre><code>from pygame import mixer\nmixer.init() #you must initialize the mixer\nalert=mixer.Sound('bell.wav')\nalert.play()\n</code></pre>\n\n<p>With pygame you have a lot of customization options, which you may additionally experiment with.</p>\n"}, {'answer_id': 46743047, 'author': 'Martin Müller', 'author_id': 6488645, 'author_profile': 'https://Stackoverflow.com/users/6488645', 'pm_score': 2, 'selected': False, 'text': "<p>Building on Barry Wark's answer...\n<code>NSBeep()</code> from AppKit works fine, but also makes the terminal/app icon in the taskbar jump.\nA few extra lines with <code>NSSound()</code> avoids that and gives the opportunity to use another sound:</p>\n\n<pre><code>from AppKit import NSSound\n#prepare sound:\nsound = NSSound.alloc()\nsound.initWithContentsOfFile_byReference_('/System/Library/Sounds/Ping.aiff', True)\n#rewind and play whenever you need it:\nsound.stop() #rewind\nsound.play()\n</code></pre>\n\n<p>Standard sound files can be found via commandline <code>locate /System/Library/Sounds/*.aiff</code>\nThe file used by <code>NSBeep()</code> seems to be <code>'/System/Library/Sounds/Funk.aiff'</code></p>\n"}, {'answer_id': 71458296, 'author': 'chrischma', 'author_id': 14157064, 'author_profile': 'https://Stackoverflow.com/users/14157064', 'pm_score': 0, 'selected': False, 'text': '<p>By the way: there is a module for that. ;-)</p>\n<p>Just install via pip:</p>\n<pre class="lang-py prettyprint-override"><code>pip3 install mac_alerts\n</code></pre>\n<p>run your sound:</p>\n<pre class="lang-py prettyprint-override"><code>from mac_alerts import alerts\nalerts.play_error() # plays an error sound\n</code></pre>\n'}, {'answer_id': 72691776, 'author': 'jitheshKuyyalil', 'author_id': 9472425, 'author_profile': 'https://Stackoverflow.com/users/9472425', 'pm_score': 0, 'selected': False, 'text': '<p>Play sound worked for me. Install using pip</p>\n<pre><code>pip3 install playsound\n</code></pre>\n<p>To play sound</p>\n<pre><code>from playsound import playsound\nplaysound(\'beep.wav\')\n</code></pre>\n<p>References:\n<a href="https://www.geeksforgeeks.org/play-sound-in-python/" rel="nofollow noreferrer">Found the examples here</a>\n<a href="https://www.soundjay.com/beep-sounds-1.html#google_vignette" rel="nofollow noreferrer">downloaded beep.wav from here</a></p>\n'}]
['https://Stackoverflow.com/questions/13941', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1615/']