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

3

30

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.

Charitacharitable answered 21/1, 2019 at 15:56 Comment(5)
Allowing tabs to notify via audio is tricky, and is something that has to be coded into the web app. If there is no obvious setting for this, then your best bet is raise this with the vendor. That being said, have you searched the web for "google collab notification"? At least one potential solution there you should rule out.Audun
@jdv Yes obviously I had searched for similar keywords for at least 30 mins without any success otherwise I wouldn't be asking here... I know what I'm doing. (go for it you'll see there is nothing, you wil find solutions related to completely different matters)Charitacharitable
Not obviously, because you didn't tell us what ressearch you did.Audun
Well I thought stackoverflow's multiple warnings against non-preresearch before asking a question here would be enough to consider this assured. I'm sorry thenCharitacharitable
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.Audun
D
57

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

Danish answered 21/1, 2019 at 17:45 Comment(3)
Well I was looking for something more of a setting in Colab. It works indeed but is a bit clunky and messing up with your code. But yeah I guess this works alright. Again, thanks a lot @Bob Smith :)Charitacharitable
@Bob Smith, I am unable to execute this code as well as the Colab Notebook. It gives error MessageError: NotSupportedError: The operation is not supported.Begrudge
I got "MessageError: NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission." I am using colab with Safari. Fixed this with "Settings for this website..." and then got the NotSupportedErrorSenhor
F
17

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.

Fair answered 24/12, 2019 at 20:23 Comment(1)
For some reason, it neither works when Colab is in background or when I switch to another tab in the same window. The colab does all the processing but doesn't play the sound until I go the tab where it is present. Could you mention any reason for this behaviour?Carolacarolan
M
2

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.

Masonite answered 19/8, 2021 at 18:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.