The block audio macro enables you to embed audio streams into your documents. Using the macro, embed self-hosted audio files or audio sources from the Internet are supported.
5-10 Minutes to read
Asciidoc macro audio
The Asciidoc block audio macro audio::
enables you to embed audio streams into your documents. Using the macro, embed self-hosted audio files or audio sources from the Internet are supported.
Syntax
The audio formats the macro supports is given by the formats supported by the browser. HTML 5 has brought sanity to audio support in the browser by adding a dedicated audio tag element <audio> and by introducing several standard audio formats, widely supported across all modern browsers.
For a canonical list of supported web audio formats and their interaction with modern browsers, see the documentation at Mozilla Developer Supported Media Formats.
audio::ocean-waves.wav[]
You can control the audio settings using additional attributes on the macro. For instance, you can offset the start time of playback using the start attribute start
and enable autoplay using the autoplay option autoplay
.
audio::ocean-waves.wav[start=60,opts=autoplay]
You can include a caption above the audio using the title attribute.
.Take a zen moment
audio::ocean-waves.wav[]
Attributes
To control the audio, following attributes are available.
Attribute | Value|s | Example | ||
---|---|---|---|---|
| User defined text |
| ||
| User-defined playback start time in seconds. |
| ||
| User-defined playback end time in seconds. |
| ||
|
|
|
HTML audio
The HTML audio tag <audio>
embeds a media player which supports audio playback into the document.
<audio src="ambient-piano.mp3" controls="">
Your browser does not support the audio tag.
</audio>
Attributes
The above example shows simple usage of the audio element <audio>
. Fimd available attributes in alphabetical order below.
Attribute | Description | ||
---|---|---|---|
| A Boolean attribute: if specified, the audio will automatically begin playback as soon as it can do so, without waiting for the entire audio file to finish downloading.
| ||
| If this attribute is present, the browser will offer controls to allow the user to control audio playback, including volume, seeking, and pause/resume playback. | ||
| The controlslist attribute, when specified, helps the browser select what controls to show for the The allowed values are | ||
| This enumerated attribute indicates whether to use CORS to fetch the related audio file. CORS-enabled resources can be reused in the The allowed values are:
When not present, the resource is fetched without a CORS request (i.e. without sending the Origin: HTTP header, preventing its non-tainted use in <canvas> elements. If invalid, it is handled as if the enumerated keyword anonymous was used. See CORS settings attributes for additional information. | ||
| A Boolean attribute used to disable the capability of remote playback in devices that are attached using wired (HDMI, DVI, etc.) and wireless technologies (Miracast, Chromecast, DLNA, AirPlay, etc.). See this proposed specification for more information. In Safari, you can use //developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/AirPlayGuide/OptingInorOutofAirPlay/OptingInorOutofAirPlay.html as a fallback. | ||
| A Boolean attribute: if specified, the audio player will automatically seek back to the start upon reaching the end of the audio. | ||
| A Boolean attribute that indicates whether the audio will be initially silenced. Its default value is | ||
| This enumerated attribute is intended to provide a hint to the browser about what the author thinks will lead to the best user experience. It may have one of the following values:
The default value is different for each browser. The spec advises it to be set to metadata.
|
Events
Event Name | Fired When |
---|---|
The input buffer of a | |
The browser can play the media, but estimates that not enough data has been loaded to play the media up to its end without having to stop for further buffering of content. | |
The browser estimates it can play the media up to its end without stopping for content buffering. | |
The rendering of an | |
The | |
The media has become empty; for example, this event is sent if the media has already been loaded (or partially loaded), and the | |
Playback has stopped because the end of the media was reached. | |
The first frame of the media has finished loading. | |
The metadata has been loaded. | |
Fired when the browser has started to load the resource. | |
Playback has been paused. | |
Playback has begun. | |
Playback is ready to start after having been paused or delayed due to lack of data. | |
The playback rate has changed. | |
A seek operation completed. | |
A seek operation began. | |
The user agent is trying to fetch media data, but data is unexpectedly not forthcoming. | |
Media data loading has been suspended. | |
The time indicated by the | |
The volume has changed. | |
Playback has stopped because of a temporary lack of data |
Codecs
The list below denotes the codecs most commonly used on the web and which file types support them. If you only need to know which codecs are possible, this is for you.
Individual browsers may or may not choose to support all of these codecs, and their support for which container types can use them may also vary. In addition, browsers may support additional codecs not included on this list.
Codec name | Full name | Container support |
---|---|---|
Advanced Audio Coding | ||
Apple Lossless Audio Codec | ||
Adaptive Multi-Rate | ||
Free Lossless Audio Codec | ||
Pulse Code Modulation (PCM) of Voice Frequencies | ||
7 kHz Audio Coding Within 64 kbps (VoIP) | ||
MPEG-1 Audio Layer III | ||
Opus | ||
Vorbis |