@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
protectednew Audiobook(entries,zipPath?):Audiobook
Defined in: node/index.ts:21
Parameters
| Parameter | Type |
|---|---|
entries | AudiobookEntry[] |
zipPath? | string |
Returns
Overrides
Properties
entries
protectedentries:AudiobookEntry[]
Defined in: node/index.ts:22
Inherited from
metadata
protectedmetadata:AudiobookMetadata={}
Defined in: base.ts:175
Inherited from
zipPath?
protectedoptionalzipPath: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
getCoverArt()
getCoverArt():
Promise<null|IPicture>
Defined in: base.ts:277
Returns
Promise<null | IPicture>
Inherited from
getDescription()
getDescription():
Promise<null|string>
Defined in: base.ts:230
Returns
Promise<null | string>
Inherited from
getFirstValue()
protectedgetFirstValue<T>(getter):Promise<null|T>
Defined in: base.ts:178
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
getter | (entry) => Promise<T> |
Returns
Promise<null | T>
Inherited from
getNarrators()
getNarrators():
Promise<string[]>
Defined in: base.ts:262
Returns
Promise<string[]>
Inherited from
getPublisher()
getPublisher():
Promise<null|string>
Defined in: base.ts:293
Returns
Promise<null | string>
Inherited from
getReleased()
getReleased():
Promise<null|string>
Defined in: base.ts:308
Returns
Promise<null | string>
Inherited from
getSubtitle()
getSubtitle():
Promise<null|string>
Defined in: base.ts:214
Returns
Promise<null | string>
Inherited from
getTitle()
getTitle():
Promise<null|string>
Defined in: base.ts:198
Returns
Promise<null | string>
Inherited from
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
| Parameter | Type |
|---|---|
authors | string[] |
Returns
Promise<void>
Inherited from
setCoverArt()
setCoverArt(
picture):Promise<void>
Defined in: node/index.ts:95
Parameters
| Parameter | Type |
|---|---|
picture | string | IPicture |
Returns
Promise<void>
Overrides
setDescription()
setDescription(
description):Promise<void>
Defined in: base.ts:241
Parameters
| Parameter | Type |
|---|---|
description | string |
Returns
Promise<void>
Inherited from
setNarrators()
setNarrators(
narrators):Promise<void>
Defined in: base.ts:271
Parameters
| Parameter | Type |
|---|---|
narrators | string[] |
Returns
Promise<void>
Inherited from
setPublisher()
setPublisher(
publisher):Promise<void>
Defined in: base.ts:302
Parameters
| Parameter | Type |
|---|---|
publisher | string |
Returns
Promise<void>
Inherited from
setReleased()
setReleased(
released):Promise<void>
Defined in: base.ts:317
Parameters
| Parameter | Type |
|---|---|
released | string |
Returns
Promise<void>
Inherited from
setSubtitle()
setSubtitle(
subtitle):Promise<void>
Defined in: base.ts:224
Parameters
| Parameter | Type |
|---|---|
subtitle | string |
Returns
Promise<void>
Inherited from
setTitle()
setTitle(
title):Promise<void>
Defined in: base.ts:208
Parameters
| Parameter | Type |
|---|---|
title | string |
Returns
Promise<void>
Inherited from
setValue()
protectedsetValue(setter):Promise<void>
Defined in: base.ts:190
Parameters
| Parameter | Type |
|---|---|
setter | (entry) => Promise<void> |
Returns
Promise<void>
Inherited from
from()
staticfrom(pathOrPathsOrData):Promise<Audiobook>
Defined in: node/index.ts:28
Parameters
| Parameter | Type |
|---|---|
pathOrPathsOrData | string | string[] | Uint8ArrayEntry | Uint8ArrayEntry[] |
Returns
Promise<Audiobook>