Skip to content

EZ Web Audio / createFont

Function: createFont()

Call Signature

createFont(url): Promise<Font>

Defined in: packages/core/src/index.ts:1078

Create a Font from a soundfont file.

A Font is a collection of sampled notes (like a piano or organ) that can be played by note name. Soundfont files contain base64-encoded audio samples for each note.

Parameters

url

string

URL to the soundfont JavaScript file

Returns

Promise<Font>

Promise resolving to a Font instance

Throws

If the soundfont cannot be loaded or decoded

Example

typescript
import { createFont } from 'ez-web-audio'

// Load a piano soundfont
const piano = await createFont('acoustic_grand_piano-mp3.js')

// Play notes by name
piano.play('C4')  // Middle C
piano.play('E4')  // E above middle C
piano.play('G4')  // G above middle C

Call Signature

createFont(audioContext, url): Promise<Font>

Defined in: packages/core/src/index.ts:1079

Create a Font from a soundfont file.

A Font is a collection of sampled notes (like a piano or organ) that can be played by note name. Soundfont files contain base64-encoded audio samples for each note.

Parameters

audioContext

BaseAudioContext

url

string

URL to the soundfont JavaScript file

Returns

Promise<Font>

Promise resolving to a Font instance

Throws

If the soundfont cannot be loaded or decoded

Example

typescript
import { createFont } from 'ez-web-audio'

// Load a piano soundfont
const piano = await createFont('acoustic_grand_piano-mp3.js')

// Play notes by name
piano.play('C4')  // Middle C
piano.play('E4')  // E above middle C
piano.play('G4')  // G above middle C