Sound alerts in Jupyter for code completion and exceptions

I often get distracted when trying to run large epochs or sections of code. Inevitably I forget that I was even training a model or get distracted for hours by my daughter. So I put together a quick sound alert that plays on the computer running Jupyter that I thought others might find helpful.

## Import up sound alert dependencies
from IPython.display import Audio, display

def allDone():
  display(Audio(url='https://sound.peal.io/ps/audios/000/000/537/original/woo_vu_luvub_dub_dub.wav', autoplay=True))
## Insert whatever audio file you want above

Execute the sound whenever you are at the end of code that takes a longer time.

allDone()

Working on also setting it up to play different sound alerts when exceptions are thrown while running code.

6 Likes

You may be interested to know you can easily create a jupyter extension that responds to start and end cell events. I set mine up to log the start time; elapsed time; and play a sound if execution time is more than 30 seconds.

2 Likes

I am having a little bit of trouble with the extension.

I have installed and enabled it with nbextensions.

For this minute long fuction, I dont see the time start or stop. It also did not make a sound.

Any advice? I’m not very familiar with juptyer extensions and that might be the trouble.

I don’t use the nbextensions tool so no idea how you add extensions to that.

I just pip install nbextensions [which is a completely different package with the same name!). Then enable with get_ipython().magic(‘load_ext cellevents’)

Your extension sounds really cool - can you please give a noob guide on how to use it?

Do I just put callevents.py in the folder with my python notebooks and then run get_ipython().magic(‘load_ext cellevents’) in the notebook? How do I make it work for all notebooks?

I created an account on this website only to thank you for this. lol it’s awesome