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

WebAudio

Extends:

Observer → WebAudio

Direct Subclass:

MediaElement

WebAudio backend

Constructor Summary

Public Constructor
public

Construct the backend

Method Summary

Public Methods
public

This is called when wavesurfer is destroyed

public

Get the audio context used by this backend or create one

public

Returns the current time in seconds relative to the audioclip'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[][]

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: Array)

Set pre-decoded peaks

public

Set the audio source playback rate.

public

setVolume(value: number)

Set the audio volume

public

Does the browser support this backend

Inherited Summary

From class Observer
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

un(event: string, fn: function)

Remove an event handler.

public

unAll()

Remove all event handlers.

Public Constructors

public constructor(params: WavesurferParams) source

Construct the backend

Override:

Observer#constructor

Params:

NameTypeAttributeDescription
params WavesurferParams

Public Methods

public destroy() source

This is called when wavesurfer is destroyed

public getAudioContext(): AudioContext source

Get the audio context used by this backend or create one

Return:

AudioContext

public getCurrentTime(): number source

Returns the current time in seconds relative to the audioclip's duration.

Return:

number

public getDuration(): number source

Used by wavesurfer.getDuration()

Return:

number

public getOfflineAudioContext(sampleRate: number): OfflineAudioContext source

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

Params:

NameTypeAttributeDescription
sampleRate number

public getPeaks(length: number, first: number, last: number): number[] | number[][] 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 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

public getPlayedPercents(): number source

Get the position from 0 to 1

Return:

number

public getPlayedTime(): number source

Get the playback position in seconds

Return:

number

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

public load(buffer: Object) source

Loaded a decoded audio buffer

Params:

NameTypeAttributeDescription
buffer Object

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}

public setFilter(filters: ...AudioNode) source

Unpacked setFilters()

Params:

NameTypeAttributeDescription
filters ...AudioNode

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

public setPeaks(peaks: Array) source

Set pre-decoded peaks

Params:

NameTypeAttributeDescription
peaks Array

public setPlaybackRate(value: number) source

Set the audio source playback rate.

Params:

NameTypeAttributeDescription
value number

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