Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 297
Atralb Avatar asked Jan 21 '19 15:01

Atralb


People also ask

How do I turn on notifications on Google Colab?

4. Get Notified of completed cell executions. Colab can notify you of completed executions even if you switch to another tab, window, or application. You can enable it via Tools → Settings → Site → Show desktop notifications (and allow browser notifications once prompted) to check it out.

Can Google colab work together?

Unfortunately, Colab is not short for Collaboration. Colab notebooks can be shared with other users and opened by multiple users at a time. If one person makes a change, the others will be able to see the change after a short delay.

Is adding audio notification when a cell completes a two-liner?

I'm sorry then You'd think so, but this is often not the case. Also, the greater point is share what you've done so people who want to help don't have to redo what you did. Adding an audio notification when a cell completes is a two-liner. For example,

What are the 10 tricks for using Google Colab?

10 tricks for a better Google Colab experience. Undo last action (inside a cell): ctrl + m + z. Find and replace: ctrl + m + h. Insert code cell above: ctrl + m + a. Insert code cell below: ctrl + m + b. Delete cell: ctrl + m + d.

How to download audio files from Google Colab?

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. For some reason, it neither works when Colab is in background or when I switch to another tab in the same window.

How to get notifications when code is executed in notebook?

I had found some ways get notified at some target lines in the notebook, say after training is completed. One is the colab browser notification feature, can be checked to true in settings. Other one is an audio solution, you just add these 2 lines of code found here to get an alarm when the code executes at any line in a cell.


3 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

like image 187
Bob Smith Avatar answered Oct 08 '22 04:10

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.

like image 43
stackoverflowuser2010 Avatar answered Oct 08 '22 04:10

stackoverflowuser2010


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.

like image 25
cagataygulten Avatar answered Oct 08 '22 06:10

cagataygulten