Skip to main content

@storyteller-platform/audiobook

A Node.js library for inspecting, modifying, and creating audiobooks.

Installation​

npm:

npm install @storyteller-platform/audiobook

yarn:

yarn add @storyteller-platform/audiobook

deno:

deno install npm:@storyteller-platform/audiobook

About​

This is a library for working with audiobooks. Audiobooks may be distributed as single audio files, folders of audio files, or ZIP archives of audio files. Publishers use audio tags inconsistently and sometimes confusingly to store metadata within audiobook files — this library provides a consistent interface for reading and writing metadata to audiobook files.

Audiobook Basics​

An audiobook may be distributed as single audio files, folders of audio files, or ZIP archives of audio files. Chapter/track information, cover art, and metadata about the audiobook is often provided as metadata within the audio files. Different publishers may use different tags to represent the same piece of metadata, and may format metadata differently (e.g. using / instead of ; to separate lists of entities).

What this library does​

@storyteller-platform/audiobook provides an API to interact with the metadata, of an audiobook publication. It provides a consistent interface that attempts to abstract away differences in metadata representations across audio formats and publishers.

Usage​

The entrypoint to the library is through the Audiobook class. An Audiobook can be constructed from existing audio data, either read from disk or already in memory as a typed array.

Reading from a single file​

import { Audiobook } from "@storyteller-platform/audiobook/node"

const audiobook = await Audiobook.from("path/to/book.m4b")
console.log(await audiobook.getTitle())

Reading from a set of files​

import { Audiobook } from "@storyteller-platform/audiobook/node"

const audiobook = await Audiobook.from([
"path/to/track1.mp3",
"path/to/track2.mp3",
"path/to/track3.mp3",
"path/to/track4.mp3",
])
console.log(await audiobook.getTitle())

Reading from an array​

import { Audiobook } from "@storyteller-platform/audiobook"

const audioData: Uint8Array = await requestAudioData()

const audiobook = await Audiobook.from({
filename: "audiobook.m4b",
data: audioData,
})

console.log(await audiobook.getTitle())

Writing to disk​

import { Audiobook } from "@storyteller-platform/audiobook/node"

const audiobook = await Audiobook.from("path/to/audiobook.m4b")
await audiobook.setTitle("S'mores for Everyone")

await audiobook.save()
audiobook.close()

Writing to a byte array​

import { Audiobook } from "@storyteller-platform/audiobook"

const audioData: Uint8Array = await requestAudioData()

const audiobook = await Audiobook.from({
filename: "audiobook.m4b",
data: audioData,
})

await audiobook.setTitle("S'mores for Everyone")

const updated = await audiobook.save()

For more details about using the API, see the API documentation.

Development​

This package lives in the Storyteller monorepo, and is developed alongside the Storyteller platform.

To get started with developing in the Storyteller monorepo, check out the development guides in the docs.

node

Audiobook​

Defined in: node/index.ts:20

Extends​

Constructors​

Constructor​

protected new Audiobook(entries, zipPath?): Audiobook

Defined in: node/index.ts:21

Parameters​
ParameterType
entriesAudiobookEntry[]
zipPath?string
Returns​

Audiobook

Overrides​

BaseAudiobook.constructor

Properties​

entries​

protected entries: AudiobookEntry[]

Defined in: node/index.ts:22

Inherited from​

BaseAudiobook.entries

metadata​

protected metadata: AudiobookMetadata = {}

Defined in: base.ts:175

Inherited from​

BaseAudiobook.metadata

zipPath?​

protected optional zipPath: string

Defined in: node/index.ts:23

Methods​

close()​

close(): void

Defined in: node/index.ts:104

Returns​

void

getAuthors()​

getAuthors(): Promise<string[]>

Defined in: base.ts:247

Returns​

Promise<string[]>

Inherited from​

BaseAudiobook.getAuthors

getCoverArt()​

getCoverArt(): Promise<null | IPicture>

Defined in: base.ts:277

Returns​

Promise<null | IPicture>

Inherited from​

BaseAudiobook.getCoverArt

getDescription()​

getDescription(): Promise<null | string>

Defined in: base.ts:230

Returns​

Promise<null | string>

Inherited from​

BaseAudiobook.getDescription

getFirstValue()​

protected getFirstValue<T>(getter): Promise<null | T>

Defined in: base.ts:178

Type Parameters​
Type Parameter
T
Parameters​
ParameterType
getter(entry) => Promise<T>
Returns​

Promise<null | T>

Inherited from​

BaseAudiobook.getFirstValue

getNarrators()​

getNarrators(): Promise<string[]>

Defined in: base.ts:262

Returns​

Promise<string[]>

Inherited from​

BaseAudiobook.getNarrators

getPublisher()​

getPublisher(): Promise<null | string>

Defined in: base.ts:293

Returns​

Promise<null | string>

Inherited from​

BaseAudiobook.getPublisher

getReleased()​

getReleased(): Promise<null | string>

Defined in: base.ts:308

Returns​

Promise<null | string>

Inherited from​

BaseAudiobook.getReleased

getSubtitle()​

getSubtitle(): Promise<null | string>

Defined in: base.ts:214

Returns​

Promise<null | string>

Inherited from​

BaseAudiobook.getSubtitle

getTitle()​

getTitle(): Promise<null | string>

Defined in: base.ts:198

Returns​

Promise<null | string>

Inherited from​

BaseAudiobook.getTitle

save()​

save(): Promise<undefined | > Uint8ArrayEntry[]>

Defined in: node/index.ts:57

Returns​

Promise<undefined | Uint8ArrayEntry[]>

setAuthors()​

setAuthors(authors): Promise<void>

Defined in: base.ts:256

Parameters​
ParameterType
authorsstring[]
Returns​

Promise<void>

Inherited from​

BaseAudiobook.setAuthors

setCoverArt()​

setCoverArt(picture): Promise<void>

Defined in: node/index.ts:95

Parameters​
ParameterType
picturestring | IPicture
Returns​

Promise<void>

Overrides​

BaseAudiobook.setCoverArt

setDescription()​

setDescription(description): Promise<void>

Defined in: base.ts:241

Parameters​
ParameterType
descriptionstring
Returns​

Promise<void>

Inherited from​

BaseAudiobook.setDescription

setNarrators()​

setNarrators(narrators): Promise<void>

Defined in: base.ts:271

Parameters​
ParameterType
narratorsstring[]
Returns​

Promise<void>

Inherited from​

BaseAudiobook.setNarrators

setPublisher()​

setPublisher(publisher): Promise<void>

Defined in: base.ts:302

Parameters​
ParameterType
publisherstring
Returns​

Promise<void>

Inherited from​

BaseAudiobook.setPublisher

setReleased()​

setReleased(released): Promise<void>

Defined in: base.ts:317

Parameters​
ParameterType
releasedstring
Returns​

Promise<void>

Inherited from​

BaseAudiobook.setReleased

setSubtitle()​

setSubtitle(subtitle): Promise<void>

Defined in: base.ts:224

Parameters​
ParameterType
subtitlestring
Returns​

Promise<void>

Inherited from​

BaseAudiobook.setSubtitle

setTitle()​

setTitle(title): Promise<void>

Defined in: base.ts:208

Parameters​
ParameterType
titlestring
Returns​

Promise<void>

Inherited from​

BaseAudiobook.setTitle

setValue()​

protected setValue(setter): Promise<void>

Defined in: base.ts:190

Parameters​
ParameterType
setter(entry) => Promise<void>
Returns​

Promise<void>

Inherited from​

BaseAudiobook.setValue

from()​

static from(pathOrPathsOrData): Promise<Audiobook>

Defined in: node/index.ts:28

Parameters​
ParameterType
pathOrPathsOrDatastring | string[] | Uint8ArrayEntry | Uint8ArrayEntry[]
Returns​

Promise<Audiobook>

entry