Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from time import time
- from IPython import get_ipython
- from IPython.display import Audio, display
- class Beeper:
- def __init__(self, threshold, **audio_kwargs):
- self.threshold = threshold
- self.start_time = None # time in sec, or None
- self.audio = audio_kwargs
- def pre_execute(self):
- if not self.start_time:
- self.start_time = time()
- def post_execute(self):
- end_time = time()
- if self.start_time and end_time - self.start_time > self.threshold:
- audio = Audio(**self.audio, autoplay=True)
- display(audio)
- self.start_time = None
- beeper = Beeper(5, filename='beep-07.wav')
- ipython = get_ipython()
- ipython.events.register('pre_execute', beeper.pre_execute)
- ipython.events.register('post_execute', beeper.post_execute)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement