Add audio to Web images
Talking Image is a JavaScript library for playing audio appended to GIF, JPEG, and PNG images. Include the talking-image.min.js on a webpage with a talking image (image with appended audio) and hear the sound come alive.
Demos be here: http://hacksparrow.github.io/talking-image/
To see the demos from the repo, make sure you have Node.js installed on your system. Clone the repo and run the demo server to see the demos. Follow these instructions:
$ git clone git@github.com:hacksparrow/talking-image.git
$ npm install
$ node demos
Then load http://localhost:3000/demos.html.
If you don't want to clone the repo, download talking-image.min.js and the files from the demo/public directory and host them on any HTTP server of your own.
Talking image refers to an image with an audio payload appended at the end of image data. Currently OGG and MP3 audio formats are supported.
You use the regular <img>
tag but add an additional attribute called data-audio
, in which you set the options. Eg: <img src="cool.gif" data-audio="autoplay loop">
.
Options for the audio
attribute
- autoplay - start playing the audio as soon as possible. If autoplay is not set, you will have to click on the image to start playing the sound.
- sync - try to sync the animation and the audio. There is no guarantee they will be in sync.
- loop - loop the audio
- volume - specify the volume. 1 for max volume. Eg:
<img src="" data-audio="volume=0.5">
Note: You can click on the image to mute the audio any time you want.
This project hosts some talking images in the public directory under the demos
directory.
The idea behind talking images is to append OGG or MP3 data to an existing image file - nothing more than that.
On Linux / Mac:
$ cat music.ogg >> funny.gif
or
$ cat beethoven.mp3 >> welcome.jpg
On Windows:
> copy /b funny.gif + music.ogg funny-music.gif
There are some 'clean' images and audio snippets in the resources
directory, play around with it.
Note: Audio file should be appended to the image file to create a valid talking file. Reversing the order will generate a corrupted file.
Images on the Web have been 'mute' so far, the technique described here and the library add sound to Web images. The 'talking' in Talking Image comes from talkies.
Now you can enjoy the audio-visual experience of Nyan Cat for infinite hours without loading a YouTube video.
Using binary data in the browser powered by jDataView and jBinary.
Copyright (c) 2012 Hage Yaapa <http://www.hacksparrow.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.