Embed audio in HTML

Revision as of 20:55, 16 February 2021 by Yug (talk | contribs) (→‎HTML5 & light javascript)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This page present various practical ways to include LinguaLibre's audio within your web applications or projects. Cases showcasted below goes from easy to more complex. You are encouraged to hack and play with them on jsfiddle, codepen or other coding pads. A larger json with filenames and some for-loop will then allow you to take full advantage of Lingualibre's large datasets.

HTML5 audio only

Given an audio file Bazinga.mp3.

<audio controls="controls">
  <source src="/to/folder/Bazinga.ogg" type="audio/ogg">
  <source src="/to/folder/Bazinga.mp3" type="audio/mpeg"><!-- fallback -->
  Your browser does not support HTML5 audio. Please download and install a modern browser.

HTML5 & light javascript

<div class="audio">
  <audio id="" preload="auto">
    <source src="" type="audio/ogg">
    Your browser does not support HTML5 audio.

  <button class="btn btn-primary">
    <span class="play"><text>⏵</text></span>
  <button class="btn btn-info" style="display:none;">
    <span class="pause"><text>⏸</text></span>
var waitTime = 150;
var playItemToggle = function(item) {
  setTimeout(function () { 
    if (item.paused) { /*item.load();*/ } 
    else { item.pause(); }
  }, waitTime);

$('.audio').on('click', function() {
  var $audio = $(this).find('audio')[0],
  $btns  = $(this).find('.btn');


Howler.js : advanced audio library

<script src="./howler-2.0.8.js"></script>
<buton id="bazingaId" class="audio">Bazinga</button>
$('.audio').on('click', function() {  
  var sound = new Howl({ src: [ '/to/folder/Bazinga.mp3','/to/folder/Bazinga.ogg' ]});;

Audio controls characters

  • &#x23e9;
  • &#x23ea;
  • &#x24eb;
  • &#x23ec;
  • &#x23ed;
  • &#x23ee;
  • &#x23ef;
  • &#x23f4;
  • &#x23f5;
  • &#x23f6;
  • &#x23f7;
  • &#x23f8;
  • &#x23f9;
  • &#x23fa;

See HTML symbol in audio and video controls