Home Manual Reference Source
import AudioRecorder from 'itslanguage/audio/audio-recorder.js'
public class | source

AudioRecorder

Audio recording component.

Constructor Summary

Public Constructor
public

constructor(options: Object)

ITSLanguage AudioRecorder.

Member Summary

Public Members
public
public
public
public
public
Private Members
private
private
private
private

Method Summary

Public Methods
public

addEventListener(name: string, handler: Function)

Add an event listener.

public

Bind a stopwatch to sync with the playing and stopping functionality of the recorder.

public

Get the audio context or create one.

public

Get the recorded audio specifications.

public

Check if the user has already given permission to access the microphone.

public

Check if there is a recording in progress.

public

record(cb: Function, disableDelay: boolean): *

Start recording microphone input until stopped.

public

Turn off all event listeners for this recorder.

public

Remove an event listener of the recorder.

public

Request microphone access.

public

Set a new recording session id.

public

stop(forced: boolean)

Stop recording microphone input.

public

Called when a chunk of audio becomes available.

public

Toggle audio playback.

Private Methods
private

_getBestRecorder(micInputGain: GainNode): *

Get a recorder object that performs audio compression, when available.

private

Logs browser compatibility for audio recording.

private

Throw an error if the user is not yet logged in.

private

_startUserMedia(stream: MediaStream): *

Audio access was granted, start analysing.

private

fireEvent(name: string, args: Object[])

Fire an event.

Public Constructors

public constructor(options: Object) source

ITSLanguage AudioRecorder.

Params:

NameTypeAttributeDescription
options Object
  • nullable: true

Override any of the default settings.

Public Members

public activeRecordingId: * source

public audioContext: * source

public canMediaDevicesGetUserMedia: boolean source

public micInput: * source

public userMediaApproval: boolean source

Private Members

private _emitter: * source

private _recorder: WebAudioRecorder | MediaRecorder source

private _settings: * source

private _stopwatch: * source

Public Methods

public addEventListener(name: string, handler: Function) source

Add an event listener. Listens to events emitted from the recorder.

Params:

NameTypeAttributeDescription
name string

Name of the event.

handler Function

Handler function to add.

public bindStopwatch(tickCb: Function): Stopwatch source

Bind a stopwatch to sync with the playing and stopping functionality of the recorder.

Params:

NameTypeAttributeDescription
tickCb Function

Callback to invoke on every tick. A tick occurs once every 100 ms.

Return:

Stopwatch

New Stopwatch object.

Throw:

Error

If _tickCb is null.

public createAudioContext(): AudioContext source

Get the audio context or create one.

Return:

AudioContext

The AudioContext created will be returned

public getAudioSpecs(): Object source

Get the recorded audio specifications.

Return:

Object

Containing audioFormat and audioParameters describing the format.

public hasUserMediaApproval(): boolean source

Check if the user has already given permission to access the microphone.

Return:

boolean

True if user has granted access to the microphone. False otherwise.

public isRecording(): boolean source

Check if there is a recording in progress.

Return:

boolean

True if user is currently recording audio. False` otherwise.

public record(cb: Function, disableDelay: boolean): * source

Start recording microphone input until stopped. By default the actual recording will start a small delay of 100ms. Set disableDelay to true to disable this delay.

Params:

NameTypeAttributeDescription
cb Function
  • nullable: true

The callback that provides a piece of raw audio when it becomes available. It may be used for streaming.

disableDelay boolean

If set to true it will disable the delay before the actual recording starts.

Return:

*

Emit:

Event

'recording' With arguments: [recording ID].

public removeAllEventListeners() source

Turn off all event listeners for this recorder.

public removeEventListener(name: string, handler: Function) source

Remove an event listener of the recorder.

Params:

NameTypeAttributeDescription
name string

Name of the event.

handler Function

Handler function to remove.

public requestUserMedia(): Promise source

Request microphone access.

Calling this function may result in thrown exceptions when browser doesn't support provide live audio input.

Return:

Promise

A promise that resolves a MediaStream object. If the user denies permission, or matching media is not available, then the promise is rejected with PermissionDeniedError or NotFoundError respectively.

Throw:

Error

If no live audio input is available or permitted.

public startRecordingSession(id: number): number source

Set a new recording session id.

Params:

NameTypeAttributeDescription
id number

When defined, stick this id to the recorded blob.

Return:

number

The id that was given or a unique generated one.

public stop(forced: boolean) source

Stop recording microphone input.

Params:

NameTypeAttributeDescription
forced boolean
  • optional
  • default: false

Set whether to force the microphone to stop recording or let it end normally.

Emit:

Event

'recorded' With arguments: [recording ID, audio Blob, forced].

public streamCallback(chunk: ArrayBuffer) source

Called when a chunk of audio becomes available.

Params:

NameTypeAttributeDescription
chunk ArrayBuffer

A chunk of audio (Int16 formatted).

public toggleRecording() source

Toggle audio playback. Switch from playing to paused state and back.

Private Methods

private _getBestRecorder(micInputGain: GainNode): * source

Get a recorder object that performs audio compression, when available.

Using the Media Stream Recording API for recording is the prefered solution. It allows recording compressed audio which makes it quicker to submit. If not available, use a default createScriptProcessor is used.

Params:

NameTypeAttributeDescription
micInputGain GainNode

The GainNode to analyze.

Return:

*

private _recordingCompatibility() source

Logs browser compatibility for audio recording. In case of compatibility issues, an error is thrown.

private _requireGetUserMedia(): boolean source

Throw an error if the user is not yet logged in.

Return:

boolean

True when permission was already granted. False otherwise.

private _startUserMedia(stream: MediaStream): * source

Audio access was granted, start analysing.

Params:

NameTypeAttributeDescription
stream MediaStream

Media Stream.

Return:

*

private fireEvent(name: string, args: Object[]) source

Fire an event.

Params:

NameTypeAttributeDescription
name string

Name of the event.

args Object[]

Arguments.