Is there a way to make Colab give an Audio Notification when cell has finished running

Question:

I am coding Neural Network models and trainings are long to run so I would like to go doing something else then go back as soon as the cell has finished running.

There is already a way to track this since the Tab Icon is grey when busy then yellow when done. But I can’t find something abut audio notifications.

Asked By: Atralb

||

Answers:

Adding an audio notification when a cell completes is a two-liner. For example,

# Play an audio beep. Any audio URL will do.
from google.colab import output
output.eval_js('new Audio("https://upload.wikimedia.org/wikipedia/commons/0/05/Beep-09.ogg").play()')

Here’s an example notebook:
https://colab.research.google.com/drive/1jrEy5V7FjzAq8Ydg22E1L72xZYsEQWlM

Edit: Colab now includes a setting that will deliver a browser notification when execution completes in the background. You can enable it in the settings like so:

enter image description here

The announcement is here: https://twitter.com/GoogleColab/status/1291775273692614659

Answered By: Bob Smith

Google Colab is built on top of Jupyter Notebook, so this code will work:

import IPython
display(IPython.display.Audio(url="https://yoursound.com/sound.mp3", autoplay=True))

A bug that I’ve found is that if my web browser (Chrome) window is minimized into the dock on my Mac OS computer, the sound does not play. However, it will play in other circumstances, such as when the window is open but not in the foreground.

You can find useful audio of English words like "done" or "complete" for alerts. Use an online dictionary that has audible pronunciations (e.g. Google or Dictionary.com), search for the word you want, use your web browser’s "Inspect" tool to look at the HTML source, and then search in the HTML for "mp3".

Here are some that I like:

https://static.sfdict.com/audio/C07/C0702600.mp3

https://ssl.gstatic.com/dictionary/static/pronunciation/2019-10-21/audio/do/done_en_us_1.mp3

https://ssl.gstatic.com/dictionary/static/sounds/20180430/complete–_us_1.mp3

You can also download the audio file to your Google Colab file system with !wget URL and then play the sound from Colab by using the local filename.

I created a python module that reminds developers on Telegram application after code execution. I guess, you can also run it in Colab. It might be more helpful than making sound. All you need is carrying your mobile phone.

Pypi link: https://pypi.org/project/devreminder/

Github link: https://github.com/cagataygulten/devreminder

Example:

In [1]>>
    from devreminder import DevReminder
    import time

In [2]>>
    remind = DevReminder(1932126911,False,0)

In [3]>>
    remind.me("Example")
    time.sleep(6)

Output:

An example of reminder message

Please follow README file for more information.

Answered By: cagataygulten