audio

package
v0.15.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2026 License: BSD-3-Clause Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AudioParser

type AudioParser struct {
	// contains filtered or unexported fields
}

Handles parsing of audiobooks from an unstructured archive format containing audio files, such as ZAB (Zipped Audio Book) or a simple ZIP. It can also work for a standalone audio file.

func NewParser

func NewParser() AudioParser

func NewRichParser

func NewRichParser(opts ...Option) AudioParser

func (AudioParser) Parse

func (p AudioParser) Parse(ctx context.Context, asset asset.PublicationAsset, fetcher fetcher.Fetcher) (*pub.Builder, error)

Parse implements PublicationParser

type Option

type Option func(*AudioParser)

Option configures an AudioParser.

func WithCacheBlockSize

func WithCacheBlockSize(size int) Option

WithCacheBlockSize sets the block size (in bytes) of the per-file read cache used while probing audio files for rich metadata. The default is 256 KiB. A value <= 0 is ignored and keeps the default. Larger blocks coalesce more reads into each range request (fewer requests, more bytes); smaller blocks transfer less when reads are scattered.

func WithConcurrency

func WithConcurrency(n int) Option

WithConcurrency sets how many audio files are probed in parallel while extracting rich metadata, and also bounds the parallel reads used within a single file (e.g. fetching the scattered chapter-title samples of an MP4 chapter track). The default is 8. A value <= 0 is ignored and keeps the default. Use 1 to probe and read fully sequentially. Note that both levels can be in flight at once, so the worst-case number of concurrent requests is roughly the square of this value.

func WithRetainedCache added in v0.15.1

func WithRetainedCache() Option

WithRetainedCache keeps the read-cache blocks fetched while probing attached to the parsed publication, so that serving its audio files answers those byte ranges — and the resources' lengths — from memory instead of new remote requests. Chapter-title samples are also pulled through the block cache (costing up to one block of extra transfer per chapter while parsing).

The retained ranges — container headers and chapter samples — are exactly what a browser's demuxer requests before starting playback of an M4B, so this trades a slightly more expensive parse for a much faster time to first audio. Recommended when the publication is opened once and served many times (e.g. an HTTP streamer in front of remote storage); wasteful for one-shot parsing, and unnecessary for local files. Memory cost is bounded by what probing touched: typically a few blocks per file plus one per chapter.

func WithoutEmbeddedChapters

func WithoutEmbeddedChapters() Option

WithoutEmbeddedChapters disables extracting the table of contents from chapter markers embedded in the audio files (e.g. an MP4 chapter track or Vorbis CHAPTER comments). This avoids the extra reads they require; the TOC then comes from a playlist or per-file titles when available.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL