Home Reference Source
import WebAudio from 'wavesurfer.js/src/webaudio.js'
public class | source

WebAudio

Extends:

Observer → WebAudio

Direct Subclass:

MediaElement

Indirect Subclass:

MediaElementWebAudio

WebAudio backend

Static Member Summary

Static Public Members
public static

scriptBufferSize: size of the processing buffer

Constructor Summary

Public Constructor
public

Construct the backend

Member Summary

Public Members
public

ac: *

ac: Audio Context instance

public

analyser: provides audio analysis information

public

audioContext: allows to process audio with WebAudio API

public

Boolean indicating if the backend was destroyed.

public

gainNode: allows to control audio volume

public

scriptNode: allows processing audio

Method Summary

Public Methods
public

Create analyser node to perform audio analysis

public

Create ScriptProcessorNode to process audio

public

Create the gain node needed to control the playback volume.

public

This is called when wavesurfer is destroyed

public

Destroy all references with WebAudio, disconnecting audio nodes and closing Audio Context

public

getAudioContext(): AudioContext

Get the audio context used by this backend or create one

public

Returns the current time in seconds relative to the audio-clip's duration.

public

Used by wavesurfer.getDuration()

public

Get the offline audio context used by this backend or create one

public

getPeaks(length: number, first: number, last: number): number[] | Number<Array[]>

Compute the max and min value of the waveform when broken into <length> subranges.

public

Returns the current playback rate.

public

Get the position from 0 to 1

public

Get the playback position in seconds

public

Get the current volume

public

init()

Initialise the backend, called in wavesurfer.createBackend()

public

Used by wavesurfer.isPlaying() and wavesurfer.playPause()

public

load(buffer: Object)

Loaded a decoded audio buffer

public

pause()

Pauses the loaded audio.

public

play(start: number, end: number)

Plays the loaded audio region.

public

seekTo(start: number, end: number): {start: number, end: number}

Used by wavesurfer.seekTo()

public

setFilter(filters: ...AudioNode)

Unpacked setFilters()

public

setFilters(filters: AudioNode[])

Insert custom Web Audio nodes into the graph

public

setLength(length: number)

Set the rendered length (different from the length of the audio)

public

setPeaks(peaks: number[] | Number<Array[]>, duration: number)

Set pre-decoded peaks

public

Set a point in seconds for playback to stop at.

version 3.3.0
public

Set the audio source playback rate.

public

setSinkId(deviceId: string): Promise

Set the sink id for the media player

public

setVolume(value: number)

Set the audio volume

public

Does the browser support this backend

Inherited Summary

From class Observer
public
public

fireEvent(event: string, args: ...any)

Manually fire an event

public

Attach a handler function for an event.

public

once(event: string, handler: function): ListenerDescriptor

Attach a handler to an event.

public

Disable firing a list of events by name.

since 4.0.0
public

un(event: string, fn: function)

Remove an event handler.

public

unAll()

Remove all event handlers.

Static Public Members

public static scriptBufferSize: * source

scriptBufferSize: size of the processing buffer

Public Constructors

public constructor(params: WavesurferParams) source

Construct the backend

Override:

Observer#constructor

Params:

NameTypeAttributeDescription
params WavesurferParams

Wavesurfer parameters

Public Members

public ac: * source

ac: Audio Context instance

public analyser: * source

analyser: provides audio analysis information

public audioContext: * source

audioContext: allows to process audio with WebAudio API

public destroyed: boolean source

Boolean indicating if the backend was destroyed.

public gainNode: * source

gainNode: allows to control audio volume

public scriptNode: * source

scriptNode: allows processing audio

Public Methods

public createAnalyserNode() source

Create analyser node to perform audio analysis

public createScriptNode() source

Create ScriptProcessorNode to process audio

public createVolumeNode() source

Create the gain node needed to control the playback volume.

public destroy() source

This is called when wavesurfer is destroyed

public destroyWebAudio() source

Destroy all references with WebAudio, disconnecting audio nodes and closing Audio Context

public getAudioContext(): AudioContext source

Get the audio context used by this backend or create one

Return:

AudioContext

Existing audio context, or creates a new one

public getCurrentTime(): number source

Returns the current time in seconds relative to the audio-clip's duration.

Return:

number

The current time in seconds

public getDuration(): number source

Used by wavesurfer.getDuration()

Return:

number

Duration of loaded buffer

public getOfflineAudioContext(sampleRate: number): OfflineAudioContext source

Get the offline audio context used by this backend or create one

Params:

NameTypeAttributeDescription
sampleRate number

The sample rate to use

Return:

OfflineAudioContext

Existing offline audio context, or creates a new one

public getPeaks(length: number, first: number, last: number): number[] | Number<Array[]> source

Compute the max and min value of the waveform when broken into <length> subranges.

Params:

NameTypeAttributeDescription
length number

How many subranges to break the waveform into.

first number

First sample in the required range.

last number

Last sample in the required range.

Return:

number[] | Number<Array[]>

Array of 2*<length> peaks or array of arrays of peaks consisting of (max, min) values for each subrange.

public getPlaybackRate(): number source

Returns the current playback rate. (0=no playback, 1=normal playback)

Return:

number

The current playback rate

public getPlayedPercents(): number source

Get the position from 0 to 1

Return:

number

Position

public getPlayedTime(): number source

Get the playback position in seconds

Return:

number

The playback position in seconds

public getVolume(): number source

Get the current volume

Return:

number

value A floating point value between 0 and 1.

public init() source

Initialise the backend, called in wavesurfer.createBackend()

public isPaused(): boolean source

Used by wavesurfer.isPlaying() and wavesurfer.playPause()

Return:

boolean

Whether or not this backend is currently paused

public load(buffer: Object) source

Loaded a decoded audio buffer

Params:

NameTypeAttributeDescription
buffer Object

Decoded audio buffer to load

public pause() source

Pauses the loaded audio.

public play(start: number, end: number) source

Plays the loaded audio region.

Params:

NameTypeAttributeDescription
start number

Start offset in seconds, relative to the beginning of a clip.

end number

When to stop relative to the beginning of a clip.

public seekTo(start: number, end: number): {start: number, end: number} source

Used by wavesurfer.seekTo()

Params:

NameTypeAttributeDescription
start number

Position to start at in seconds

end number

Position to end at in seconds

Return:

{start: number, end: number}

Object containing start and end positions

public setFilter(filters: ...AudioNode) source

Unpacked setFilters()

Params:

NameTypeAttributeDescription
filters ...AudioNode

One or more filters to set

public setFilters(filters: AudioNode[]) source

Insert custom Web Audio nodes into the graph

Params:

NameTypeAttributeDescription
filters AudioNode[]

Packed filters array

Example:

const lowpass = wavesurfer.backend.ac.createBiquadFilter();
wavesurfer.backend.setFilter(lowpass);

public setLength(length: number) source

Set the rendered length (different from the length of the audio)

Params:

NameTypeAttributeDescription
length number

The rendered length

public setPeaks(peaks: number[] | Number<Array[]>, duration: number) source

Set pre-decoded peaks

Params:

NameTypeAttributeDescription
peaks number[] | Number<Array[]>

Peaks data

duration number
  • nullable: true

Explicit duration

public setPlayEnd(end: number) version 3.3.0 source

Set a point in seconds for playback to stop at.

Params:

NameTypeAttributeDescription
end number

Position to end at

public setPlaybackRate(value: number) source

Set the audio source playback rate.

Params:

NameTypeAttributeDescription
value number

The playback rate to use

public setSinkId(deviceId: string): Promise source

Set the sink id for the media player

Params:

NameTypeAttributeDescription
deviceId string

String value representing audio device id.

Return:

Promise

A Promise that resolves to undefined when there are no errors.

public setVolume(value: number) source

Set the audio volume

Params:

NameTypeAttributeDescription
value number

A floating point value between 0 and 1.

public supportsWebAudio(): boolean source

Does the browser support this backend

Return:

boolean

Whether or not this browser supports this backend