def speak(text):
from IPython.display import Javascript as js, clear_output
# Escape single quotes
text = text.replace("'", r"\'")
display(js(f'''
if(window.speechSynthesis) {{
var synth = window.speechSynthesis;
synth.speak(new window.SpeechSynthesisUtterance('{text}'));
}}
'''))
# Clear the JS so that the notebook doesn't speak again when reopened/refreshed
clear_output(False)
for i in range(int(1e8)): pass
speak("I'm done with the first loop.")
for i in range(int(1e8)): pass
speak("Now I'm really done!")