I was doing some audio analysis stuff with Jupyter and tried to play .ogg
files with IPython.display.Audio
. Since PyCharm often failed to open big .ipynb
files, I mostly used web browser to view my Notebook files at localhost:8888
.
This picture is what I get with Chrome. As you can see, FailToDisplay.ogg is taken from my work, the audio play bar is not activated. File-ACDC_-_Back_In_Black-sample.ogg and song sample.mp3 are all downloaded from Internet. The integrity of 3 files are all validated, i.e., they can all be played correctly with audio players.
I also tested it with Microsoft Edge and Firefox, and the results are mostly the same. 2 .ogg
playbars are all inactive while .mp3
playbar is active and works perfectly. So I guess the problem is not web browser dependent.
I checked the html source code of these 3 audio playbars with Chrome Developer Tool, they are all like:
<audio controls="controls">
<source src="data:None;base64,VERYLONGTEXT" type="None">
Your browser does not support the audio element.
</audio>
The type
for mp3 is audio/mpeg
and type
for ogg is None
. After some google search, I guess this has something to do with MIME type. So I inspected 3 audio files with command mimetype
:
$ mimetype ./*
./AudioDisplayErrorTest.ipynb: text/plain
./FailToDisplay.ogg: audio/x-vorbis+ogg
./File-ACDC_-_Back_In_Black-sample.ogg: video/x-theora+ogg
./song sample.mp3: audio/mpeg
Not very strange. Then I find this blog post How to set MIMETYPES on server : Forums : PythonAnywhere and tested my python MIME type settings:
>>> import mimetypes
>>> mimetypes.guess_type("foo.ogg")
(None, None)
Now I don't know what to do next with this kind of situation. Is this just a bug of Jupyter or IPython or system-wide? Where can I change this behavior?
My Python environment settings are
audioread==2.1.4
ipykernel==4.4.1
ipython==5.1.0
ipython-genutils==0.1.0
ipywidgets==4.1.1
jupyter==1.0.0
jupyter-client==4.3.0
jupyter-console==5.0.0
jupyter-core==4.1.1
librosa==0.4.3
nbconvert==4.2.0
nbformat==4.0.1
notebook==4.2.2
numpy==1.11.1
openpyxl==2.3.2
pydub==0.16.5