Search code examples
pythonhtml5-audiopython-sphinx

Is it possible to embed an audio file in the html output of the Sphinx documentation tool?


There probably isn't a specific directive for embedding audio files in the html output, but is it possible to at least embed an html code that does this, such as:

<audio controls="controls">
  <source src="foo.wav" type="audio/wav">
  Your browser does not support the <code>audio</code> element. 
</audio>

And, if yes, how?

Update: OK, I managed to solve this, simply adding this to the .rst document:

.. raw:: html

   <audio controls="controls">
         <source src="_static/foo.wav" type="audio/wav">
         Your browser does not support the <code>audio</code> element. 
   </audio>

But, I had to manually copy the foo.wav file into _build/html/_static. This isn't that bad, but I was wondering whether this can be done automatically and if I can keep the audio files, say in, audio directory inside the docs root dir...?!?


Solution

  • Use the raw directive.

    .. raw:: html
    
        <audio controls="controls">
          <source src="foo.wav" type="audio/wav">
          Your browser does not support the <code>audio</code> element. 
        </audio>