Skip to content

Instantly share code, notes, and snippets.

@Yjejuy
Created April 25, 2024 09:37
Show Gist options
  • Select an option

  • Save Yjejuy/e8fd613c8d44704ef422be6d55420267 to your computer and use it in GitHub Desktop.

Select an option

Save Yjejuy/e8fd613c8d44704ef422be6d55420267 to your computer and use it in GitHub Desktop.
Play a Super Mario theme music as a notification for jupyter notebook
def mario_sound():
from IPython.lib.display import Audio
import numpy as np
framerate = 4410
play_time_seconds = 1
C, G, E, p = 261.63, 392.00, 329.63, 0.0
mute_rate = 0.1
def generatenote(name, relative):
t = play_time_seconds * relative
st = np.linspace(0, t * (1 - mute_rate) , int(framerate*t*(1-mute_rate)))
mt = np.linspace(0, t * mute_rate, int(framerate*t*mute_rate))
sample = np.concatenate([np.sin(2*np.pi*name*st), np.sin(2*np.pi*mt) ])
return sample
def concatenate_notes(notes):
return np.concatenate([ generatenote(note, r) for note, r in notes])
audio_data = concatenate_notes([(E,1/8), (E,1/8), (p, 1/8),(E, 1/8),(p, 1/8), (C, 1/8), (E, 1/4), (G, 1/4),(p, 1/4),( G / 2, 1/4)])
return Audio(audio_data, rate=framerate, autoplay=True)
mario_sound()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment