Play a sound in Jupyter Notebook

Found this thread actually looking for how to have a player widget on a notebook, ended up with this after a python example:

using WAV
wavwrite(0.4*rand(2000, 2), "example2.wav", Fs=44100.0)

audioplayer(filepath) = """
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Simple Test</title>
    </head>
    
    <body>
    <audio controls="controls" style="width:600px" >
      <source src="$filepath" type="audio/wav" />
      Your browser does not support the audio element.
    </audio>
    </body>
    """

display("text/html", audioplayer("example2.wav"))
2 Likes