Skip to content

Instantly share code, notes, and snippets.

@tamsanh
Created April 6, 2018 03:18
Show Gist options
  • Save tamsanh/a658c1b29b8cba7d782a8b3aed685a24 to your computer and use it in GitHub Desktop.
Save tamsanh/a658c1b29b8cba7d782a8b3aed685a24 to your computer and use it in GitHub Desktop.
Generate and play a sound in Jupyter Notebook when then cell is run. Useful as notification when a long-running cell is done.
from IPython.lib.display import Audio
import numpy as np
framerate = 4410
play_time_seconds = 3
t = np.linspace(0, play_time_seconds, framerate*play_time_seconds)
audio_data = np.sin(2*np.pi*300*t) + np.sin(2*np.pi*240*t)
Audio(audio_data, rate=framerate, autoplay=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment