Listen to this
Overview
Your browser doesn’t support HTML5 audio
I would like (for every section on each post) a button near the vertical scroll bar on the right so that when a visitor mouses over it or clicks on it, text from that section would be verbally read aloud.
The sound files would be created by Text-To-Speech software reading markup text.
I haven’t figured it all out yet, but below is what I’ve found so far.
If you want to skip the drama in the background history, click here to the solutions.
Early fragmentation
BGSOUND tag
Many of the instructions for “mouseover sound”
show use of playSound
and stopSound
functions with tags such as:
But this is recognized only by Internet Explorer.
EMBED tag
Early Netscape Navigator versions introduced the LiveAudio plugin with this BODY tag:
This is controlled by onClick functions
document.mySound.play()
and
stop()
.
Alternately, a JavaScript function to insert in the DOM (from http://jsfiddle.net/zHfrP/):
This function would be invoked by HTML such as this:
OBJECT tag
Early Firefox, Safari, and Google Chrome browsers relied on plugins such as Apple QuickTime that recognized OBJECT tags:
Adobe Flash plug-in
Adobe Flash provided cross-browser audio and video functionality to early HTML4 browsers. But it involved users installing and updating plug-ins which also provided a vector for viruses.
That’s now 4 different ways to play sound. Then there’s one more:
Modern audio tag
If you want to be annoying, specify:
To provide a player control, add this element:
To provide mouse-over to play, add JavaScript:
Different File Formats in HTML5
The HTML5 standard spec for browsers includes the
<audio>
and <video>
tags built-in, so no plug-in is needed, theoretically.
But due to licensing issues, different browsers support different file formats.
There are several different audio file formats:
Browser | mid | wav | mp3 | mp4 | ogg |
---|---|---|---|---|---|
IE 9+ | X | - | X | - | - |
Firefox 3.5+ | - | X | - | - | X |
Chrome 6+ | - | - | X | X | X |
Safari 5+ | - | X | X | X | - |
Opera 10.5+ | - | X | - | - | X |
Since most browsers support more than one format, only two formats of each file need to be provided on a website to cover all the major browsers out there: .mp3 and .ogg.
Additionally, Adobe Flash supports its own Real-time file format.
Solutions
SoundManager2
The simplest approach is to make use of SoundManager2 because it has invisiable fall-back for older browsers (swf files processed by Adobe Flash plug-ins).
Here are the steps I took to change my Jekyll site:
-
Create a tts (text to speech) folder in your website repo to hold sound files.
-
Download the zip file from:
-
Unzip.
The unzipped folder contains all resources for the demo website, such as index.html, which is not needed.
-
Copy the swf folder to your website repo.
Only one edition of the .js file is needed from the script folder.
-
Copy to your website root folder just the production-optimized, with debug code removed:
soundmanager2-nodebug-jsmin.js
-
To the bottom of _scripts.html within the _includes folder, so it’s included before
</body>
at the bottom of page.html.
QUESTION: Is there a cloud version of SoundManager?
- Create a Liquid module
-
In each .md file where a sound button is needed:
{% include tts1.html %}
- Run in debug mode
AMP (Accelerated Mobile Pages)
This is the one I’m using.
Your browser doesn’t support HTML5 audio
Your browser doesn’t support HTML5 audio
Text to speech
Paste text online to create an mp3 file:
- http://www.coolutils.com/Online/Audio-Converter/
mp3 to ogg conversion
WARNING: Both MP3 and OGG are lossy formats, unlike WAV or FLAC. So quality will degrade when processed.
PROTIP: During MP3-to-OGG conversion, minimize poor quality in the generated file by using a higher destination bitrate than the source bitrate For example, for MP3s recorded at 128 kbps, create Ogg using -q7 (variable bitrate level 7), which is usually around ~200 kbps.
To convert mp3 to ogg in batch mode, download the avconv tarball
http://superuser.com/questions/568464/how-to-install-libav-avconv-on-osx
This program is a fork of deprecated FFMPEG.
In the folder containing mp3 files, use String Manipulation to loop through files ending with mp3:
- Alternately, http://manpages.ubuntu.com/manpages/precise/en/man1/dir2ogg.1.html on Ubuntu:
If you only have one mp3 file to convert to ogg, do it online:
- http://audio.online-convert.com/convert-to-ogg
Resources
Here are some resources referenced on this page:
http://stackoverflow.com/questions/10105063/how-to-play-a-notification-sound-on-websites