Audio extension

VersionDownloads

This extension adds support for native <audio> elements in the editor, allowing you to embed audio files directly into your documents.

Install

npm install @tiptap/extension-audio

Settings

addPasteHandler

Controls if the paste handler for audio sources should be added.

Default: true

Audio.configure({
  addPasteHandler: false,
})

autoplay

Controls if the audio should autoplay.

Default: false

Audio.configure({
  autoplay: true,
})

controls

Controls if the audio element should render the native controls.

Default: true

Audio.configure({
  controls: false,
})

loop

Controls if the audio should loop.

Default: false

Audio.configure({
  loop: true,
})

muted

Controls if the audio should be muted.

Default: false

Audio.configure({
  muted: true,
})

preload

The preload behavior for the audio element.

Default: 'metadata'

Audio.configure({
  preload: 'none',
})

controlslist

Provides the controlslist attribute for the audio element.

Default: undefined

Audio.configure({
  controlslist: 'nodownload',
})

crossorigin

Sets the crossorigin attribute for the audio element.

Default: undefined

Audio.configure({
  crossorigin: 'anonymous',
})

disableRemotePlayback

Controls if remote playback should be disabled on the audio element.

Default: false

Audio.configure({
  disableRemotePlayback: true,
})

allowBase64

Allows data: URLs for audio sources.

Default: false

Audio.configure({
  allowBase64: true,
})

HTMLAttributes

Custom HTML attributes that should be added to the rendered HTML tag.

Audio.configure({
  HTMLAttributes: {
    class: 'my-custom-class',
  },
})

inline

Controls if the audio node should be inline or not.

Default: false

Audio.configure({
  inline: true,
})

Commands

setAudio(options)

Inserts an audio element at the current position with the specified options. The audio element will be embedded as a block-level node by default, but can be configured to be inline.

editor.commands.setAudio({
  src: 'https://example.com/audio.mp3',
  controls: true,
  autoplay: false,
})

Options

OptionDescriptionOptionalDefault
srcThe URL of the audio file to embed-
controlsShow native audio controls (play, pause, volume, etc.)true
autoplayAutomatically start playing the audio when the page loadsfalse
loopLoop the audio playback continuouslyfalse
mutedStart the audio in a muted statefalse
preloadHow the audio should be loaded ('auto', 'metadata', 'none', or null)'metadata'
controlslistComma-separated list of controls to hide (e.g., 'nodownload')undefined
crossoriginCORS setting for the audio element ('anonymous', 'use-credentials', or '')undefined
disableRemotePlaybackDisable remote playback on supported devicesfalse
HTMLAttributesAdditional HTML attributes to apply to the audio element

Source code

packages/extension-audio/