- AudioEffects
Advanced audio effects including gapless playback, crossfade, and bit-perfect mode
- AudioPlayer
Modular Node.js Lossless Audio Player (PortAudio + FFmpeg)
- DeviceManager
Manages audio device selection and configuration
- PlaylistManager
Manages playlist operations including shuffle, repeat, and navigation
- StreamManager
Manages HTTP/HTTPS streaming with buffering, reconnection, and error handling
- Zeaker
Node.js Lossless Audio Player (PortAudio + FFmpeg) - Modular Entry Point
- AudioUtils
Audio processing and format utilities
- ErrorHandler
Centralized error handling utilities for the audio player
- FFmpegUtils
FFmpeg-related utilities for audio processing
- getAudioStreamInfo(ffprobePath, filePath) ⇒
Promise.<{sampleRate: number, channels: number, bitDepth: number, duration: number}> Get audio stream info (sample rate, channels, bit depth, duration) from a file using ffprobe.
Advanced audio effects including gapless playback, crossfade, and bit-perfect mode
Author: zevinDev
- AudioEffects
- .AudioEffects
- .setBitPerfect(options) ⇒
object - .isBitPerfectMode() ⇒
boolean - .setCrossfadeDuration(duration)
- .setCrossfadeCurve(curve)
- .getCrossfadeConfig() ⇒
object - .prebufferNextTrack(nextTrack, ffmpegPath, [audioFormat]) ⇒
Promise.<object> - .createCrossfade(currentBuffers, nextBuffers, sampleRate, channels, [duration]) ⇒
Array.<Buffer> - .waitForGaplessReady([timeoutMs]) ⇒
Promise.<boolean> - .getGaplessBuffers() ⇒
Array.<Buffer>|null - .cleanupGapless()
- .getEffectAvailability() ⇒
object - .validateEffectAvailability(effectName)
- .getConfiguration() ⇒
object
- .setBitPerfect(options) ⇒
- .AudioEffects
AudioEffects handles advanced audio processing features. Manages gapless playback, crossfade transitions, and bit-perfect mode.
Kind: static class of AudioEffects
Author: zevinDev
- .AudioEffects
- .setBitPerfect(options) ⇒
object - .isBitPerfectMode() ⇒
boolean - .setCrossfadeDuration(duration)
- .setCrossfadeCurve(curve)
- .getCrossfadeConfig() ⇒
object - .prebufferNextTrack(nextTrack, ffmpegPath, [audioFormat]) ⇒
Promise.<object> - .createCrossfade(currentBuffers, nextBuffers, sampleRate, channels, [duration]) ⇒
Array.<Buffer> - .waitForGaplessReady([timeoutMs]) ⇒
Promise.<boolean> - .getGaplessBuffers() ⇒
Array.<Buffer>|null - .cleanupGapless()
- .getEffectAvailability() ⇒
object - .validateEffectAvailability(effectName)
- .getConfiguration() ⇒
object
- .setBitPerfect(options) ⇒
Enable or disable bit-perfect output mode. When enabled, disables all PCM manipulation (volume, crossfade, gapless, visualization, etc.).
Kind: instance method of AudioEffects
Returns: object - Configuration result
Throws:
ErrorIf configuration fails
Author: zevinDev
| Param | Type | Default | Description |
|---|---|---|---|
| options | boolean | object |
true |
Pass true to enable, false to disable, or an object: { enable: boolean, sampleRate?: number, bitDepth?: number } |
Check if bit-perfect mode is enabled.
Kind: instance method of AudioEffects
Returns: boolean - True if bit-perfect mode is enabled
Author: zevinDev
Set the crossfade duration for crossfade transitions.
Kind: instance method of AudioEffects
Throws:
ErrorIf duration is invalid or in bit-perfect mode
Author: zevinDev
| Param | Type | Description |
|---|---|---|
| duration | number |
Crossfade duration in seconds (must be >= 0) |
Set the crossfade curve for crossfade transitions.
Kind: instance method of AudioEffects
Throws:
ErrorIf curve is invalid or in bit-perfect mode
Author: zevinDev
| Param | Type | Description |
|---|---|---|
| curve | string |
Crossfade curve name |
Get current crossfade configuration.
Kind: instance method of AudioEffects
Returns: object - Crossfade configuration
Author: zevinDev
Pre-buffer the next track's PCM data for gapless playback.
Kind: instance method of AudioEffects
Returns: Promise.<object> - Prebuffering result with buffers and control functions
Throws:
ErrorIf prebuffering fails
Author: zevinDev
| Param | Type | Description |
|---|---|---|
| nextTrack | string |
Path to the next audio file |
| ffmpegPath | string |
Path to ffmpeg binary |
| [audioFormat] | object |
Audio format settings |
audioEffects.createCrossfade(currentBuffers, nextBuffers, sampleRate, channels, [duration]) ⇒ Array.<Buffer>
Create crossfade effect between two tracks.
Kind: instance method of AudioEffects
Returns: Array.<Buffer> - Mixed PCM buffers for crossfade
Throws:
ErrorIf crossfade creation fails or bit-perfect mode is enabled
Author: zevinDev
| Param | Type | Description |
|---|---|---|
| currentBuffers | Array.<Buffer> |
PCM buffers from current track |
| nextBuffers | Array.<Buffer> |
PCM buffers from next track |
| sampleRate | number |
Audio sample rate |
| channels | number |
Number of audio channels |
| [duration] | number |
Crossfade duration (uses configured duration if not specified) |
Wait for gapless track to be ready with timeout.
Kind: instance method of AudioEffects
Returns: Promise.<boolean> - True if ready, false if timeout
Author: zevinDev
| Param | Type | Default | Description |
|---|---|---|---|
| [timeoutMs] | number |
2000 |
Timeout in milliseconds |
Get gapless playback buffers if ready.
Kind: instance method of AudioEffects
Returns: Array.<Buffer> | null - PCM buffers or null if not ready
Author: zevinDev
Clean up gapless playback resources.
Kind: instance method of AudioEffects
Author: zevinDev
Check if advanced effects are available (not in bit-perfect mode).
Kind: instance method of AudioEffects
Returns: object - Availability status for each effect
Author: zevinDev
Validate if an effect can be used in current mode.
Kind: instance method of AudioEffects
Throws:
ErrorIf effect is not available in current mode
Author: zevinDev
| Param | Type | Description |
|---|---|---|
| effectName | string |
Name of the effect to validate |
Get current audio effects configuration.
Kind: instance method of AudioEffects
Returns: object - Complete effects configuration
Author: zevinDev
Modular Node.js Lossless Audio Player (PortAudio + FFmpeg)
Author: zevinDev
- AudioPlayer
- .AudioPlayer
- instance
- .play(filePath, [startPosition]) ⇒
Promise.<void> - .pause() ⇒
Promise.<void> - .resume() ⇒
Promise.<void> - .stop() ⇒
Promise.<void> - .seek(positionSeconds) ⇒
Promise.<void> - .setVolume(level) ⇒
Promise.<void> - .getVolume() ⇒
number - .getMetadata() ⇒
Promise.<Object> - .getDuration() ⇒
number|null - .playPlaylist(playlist) ⇒
Promise.<void> - .skip() ⇒
Promise.<void> - .previous() ⇒
Promise.<void> - .stopPlaylist() ⇒
void - .setPlaylistShuffle([enable]) ⇒
void - .setPlaylistRepeat(mode) ⇒
void - .playGapless(nextTrack) ⇒
Promise.<void> - .crossfadeTo(nextTrack, [duration]) ⇒
Promise.<void> - .playStream(url, [options]) ⇒
Promise.<void> - .setOutputDevice(deviceIndex) ⇒
Promise.<void> - .setBitPerfect(options) ⇒
Promise.<void> - .onVisualization(callback) ⇒
void - .setBufferSize(frames) ⇒
void - .setCrossfadeDuration(duration) ⇒
void - .setCrossfadeCurve(curve) ⇒
void - .getStatus() ⇒
object - .getManagers() ⇒
object - .getCurrentTime() ⇒
number
- .play(filePath, [startPosition]) ⇒
- static
- .listOutputDevices() ⇒
Promise.<Array> - .testSineWave() ⇒
Promise.<void>
- .listOutputDevices() ⇒
- instance
- .AudioPlayer
Kind: static class of AudioPlayer
- .AudioPlayer
- instance
- .play(filePath, [startPosition]) ⇒
Promise.<void> - .pause() ⇒
Promise.<void> - .resume() ⇒
Promise.<void> - .stop() ⇒
Promise.<void> - .seek(positionSeconds) ⇒
Promise.<void> - .setVolume(level) ⇒
Promise.<void> - .getVolume() ⇒
number - .getMetadata() ⇒
Promise.<Object> - .getDuration() ⇒
number|null - .playPlaylist(playlist) ⇒
Promise.<void> - .skip() ⇒
Promise.<void> - .previous() ⇒
Promise.<void> - .stopPlaylist() ⇒
void - .setPlaylistShuffle([enable]) ⇒
void - .setPlaylistRepeat(mode) ⇒
void - .playGapless(nextTrack) ⇒
Promise.<void> - .crossfadeTo(nextTrack, [duration]) ⇒
Promise.<void> - .playStream(url, [options]) ⇒
Promise.<void> - .setOutputDevice(deviceIndex) ⇒
Promise.<void> - .setBitPerfect(options) ⇒
Promise.<void> - .onVisualization(callback) ⇒
void - .setBufferSize(frames) ⇒
void - .setCrossfadeDuration(duration) ⇒
void - .setCrossfadeCurve(curve) ⇒
void - .getStatus() ⇒
object - .getManagers() ⇒
object - .getCurrentTime() ⇒
number
- .play(filePath, [startPosition]) ⇒
- static
- .listOutputDevices() ⇒
Promise.<Array> - .testSineWave() ⇒
Promise.<void>
- .listOutputDevices() ⇒
- instance
Play an audio file using FFmpeg for decoding and PortAudio for output. Uses async streaming with buffer management and robust error handling.
Kind: instance method of AudioPlayer
Returns: Promise.<void> - Resolves when playback starts.
Throws:
TypeErrorIf filePath is not a string or startPosition is invalid.ErrorIf playback fails or FFmpeg/PortAudio is not available.
Author: zevinDev
| Param | Type | Default | Description |
|---|---|---|---|
| filePath | string |
Path to the audio file to play. | |
| [startPosition] | number |
0 |
Position in seconds to start playback from. |
Example
await player.play('track.flac', 10); // Start at 10 secondsPause playback.
Kind: instance method of AudioPlayer
Returns: Promise.<void> - Resolves when playback is paused.
Throws:
ErrorIf pause fails.
Emits: AudioPlayer#event:pause
Author: zevinDev
Resume playback.
Kind: instance method of AudioPlayer
Returns: Promise.<void> - Resolves when playback resumes.
Throws:
ErrorIf resume fails.
Emits: AudioPlayer#event:resume
Author: zevinDev
Stop playback and clean up resources.
Kind: instance method of AudioPlayer
Returns: Promise.<void> - Resolves when playback is stopped.
Throws:
ErrorIf stop fails.
Emits: AudioPlayer#event:stop
Author: zevinDev
Seek to a specific position in the current track.
Kind: instance method of AudioPlayer
Returns: Promise.<void> - Resolves when seek is complete.
Throws:
ErrorIf seeking fails or no track loaded.
Emits: AudioPlayer#event:seek
Author: zevinDev
| Param | Type | Description |
|---|---|---|
| positionSeconds | number |
Position in seconds to seek to. |
Set playback volume.
Kind: instance method of AudioPlayer
Returns: Promise.<void> - Resolves when volume is set.
Throws:
ErrorIf setting volume fails or in bit-perfect mode.
Author: zevinDev
| Param | Type | Description |
|---|---|---|
| level | number |
Volume level between 0.0 and 1.0. |
Get current volume level.
Kind: instance method of AudioPlayer
Returns: number - Current volume (0.0-1.0).
Author: zevinDev
Extract metadata from the current track.
Kind: instance method of AudioPlayer
Returns: Promise.<Object> - Metadata object for the current track.
Throws:
ErrorIf extraction fails or no track loaded.
Get current track duration in seconds.
Kind: instance method of AudioPlayer
Returns: number | null - Duration in seconds, or null if unknown.
Author: zevinDev
Play a playlist of audio files sequentially.
Kind: instance method of AudioPlayer
Returns: Promise.<void> - Resolves when playlist starts.
Throws:
ErrorIf playlist is invalid or playback fails.
Emits: AudioPlayer#event:playlistEnd
Author: zevinDev
| Param | Type | Description |
|---|---|---|
| playlist | Array.<string> |
Array of file paths to play. |
Skip to the next track in the playlist.
Kind: instance method of AudioPlayer
Returns: Promise.<void> - Resolves when next track starts.
Author: zevinDev
Skip to the previous track in the playlist.
Kind: instance method of AudioPlayer
Returns: Promise.<void> - Resolves when previous track starts.
Author: zevinDev
Stop playlist playback and current track.
Kind: instance method of AudioPlayer
Author: zevinDev
Enable or disable shuffle mode for playlists.
Kind: instance method of AudioPlayer
Author: zevinDev
| Param | Type | Default | Description |
|---|---|---|---|
| [enable] | boolean |
true |
Enable shuffle if true. |
Set repeat mode for playlists.
Kind: instance method of AudioPlayer
Throws:
ErrorIf invalid repeat mode.
Author: zevinDev
| Param | Type | Default | Description |
|---|---|---|---|
| mode | 'off' | 'one' | 'all' |
off |
Repeat mode. |
Enable gapless playback for the next track.
Kind: instance method of AudioPlayer
Returns: Promise.<void> - Resolves when gapless transition is set up.
Throws:
ErrorIf bit-perfect mode is enabled or no active stream.
Author: zevinDev
| Param | Type | Description |
|---|---|---|
| nextTrack | string |
Path to the next audio file. |
Crossfade between the current and next track.
Kind: instance method of AudioPlayer
Returns: Promise.<void> - Resolves when crossfade is complete.
Throws:
ErrorIf bit-perfect mode is enabled or no active stream.
Author: zevinDev
| Param | Type | Default | Description |
|---|---|---|---|
| nextTrack | string |
Path to the next audio file. | |
| [duration] | number |
3 |
Crossfade duration in seconds. |
Play from a streaming source (e.g., internet radio).
Kind: instance method of AudioPlayer
Returns: Promise.<void> - Resolves when streaming starts.
Throws:
ErrorIf streaming fails.
Author: zevinDev
| Param | Type | Description |
|---|---|---|
| url | string |
Streaming source URL. |
| [options] | object |
Streaming options. |
Set the output device for playback.
Kind: instance method of AudioPlayer
Returns: Promise.<void> - Resolves when device is set.
Throws:
ErrorIf device is not found or not output-capable.
Emits: AudioPlayer#event:deviceChange
Author: zevinDev
| Param | Type | Description |
|---|---|---|
| deviceIndex | number |
Device index to use for output. |
Enable or disable bit-perfect output mode.
Kind: instance method of AudioPlayer
Returns: Promise.<void> - Resolves when bit-perfect mode is set.
Throws:
ErrorIf currently playing and unable to restart.
Author: zevinDev
| Param | Type | Default | Description |
|---|---|---|---|
| options | boolean | object |
true |
Bit-perfect options or true to enable. |
Attach a visualization callback for PCM data.
Kind: instance method of AudioPlayer
Author: zevinDev
| Param | Type | Description |
|---|---|---|
| callback | function |
Function to receive PCM data. |
Set buffer size/latency for playback.
Kind: instance method of AudioPlayer
Author: zevinDev
| Param | Type | Description |
|---|---|---|
| frames | number |
Buffer size in frames. |
Set the crossfade duration.
Kind: instance method of AudioPlayer
Emits: AudioPlayer#event:crossfadeConfigChange
Author: zevinDev
| Param | Type | Description |
|---|---|---|
| duration | number |
Duration in seconds. |
Set the crossfade curve.
Kind: instance method of AudioPlayer
Emits: AudioPlayer#event:crossfadeConfigChange
Author: zevinDev
| Param | Type | Description |
|---|---|---|
| curve | string |
Curve type. |
Get current playback status.
Kind: instance method of AudioPlayer
Returns: object - Playback status object with isPlaying, isPaused, currentTrack, etc.
Author: zevinDev
Get manager instances for advanced usage.
Kind: instance method of AudioPlayer
Returns: object - Object containing device, playlist, effects, and stream managers.
Author: zevinDev
Get current playback time in seconds.
Kind: instance method of AudioPlayer
Returns: number - Elapsed playback time in seconds.
Author: zevinDev
List available PortAudio output devices.
Kind: static method of AudioPlayer
Returns: Promise.<Array> - Array of device objects.
Author: zevinDev
Test PortAudio output with a synchronous 440Hz sine wave (2 seconds). Useful for debugging C++/Electron buffer issues.
Kind: static method of AudioPlayer
Returns: Promise.<void> - Resolves when test is complete.
Author: zevinDev
Manages audio device selection and configuration
Author: zevinDev
- DeviceManager
- .DeviceManager
- ._initPortAudio() ⇒
Promise.<void> - .listOutputDevices() ⇒
Promise.<Array.<{index: number, name: string, maxOutputChannels: number, defaultSampleRate: number}>> - .setOutputDevice(deviceIndex) ⇒
Promise.<object> - .getCurrentDevice() ⇒
object|null - .getDefaultDevice() ⇒
Promise.<object> - .findDeviceByName(deviceName, [exactMatch]) ⇒
Promise.<(object|null)> - .validateDeviceCapabilities(device, requirements) ⇒
object - .getPortAudio() ⇒
Promise.<object>
- ._initPortAudio() ⇒
- .DeviceManager
DeviceManager handles audio device discovery and selection. Supports robust device selection across all PortAudio device types.
Kind: static class of DeviceManager
Author: zevinDev
- .DeviceManager
- ._initPortAudio() ⇒
Promise.<void> - .listOutputDevices() ⇒
Promise.<Array.<{index: number, name: string, maxOutputChannels: number, defaultSampleRate: number}>> - .setOutputDevice(deviceIndex) ⇒
Promise.<object> - .getCurrentDevice() ⇒
object|null - .getDefaultDevice() ⇒
Promise.<object> - .findDeviceByName(deviceName, [exactMatch]) ⇒
Promise.<(object|null)> - .validateDeviceCapabilities(device, requirements) ⇒
object - .getPortAudio() ⇒
Promise.<object>
- ._initPortAudio() ⇒
Initialize PortAudio and cache reference.
Kind: instance method of DeviceManager
Throws:
ErrorIf PortAudio is not available
deviceManager.listOutputDevices() ⇒ Promise.<Array.<{index: number, name: string, maxOutputChannels: number, defaultSampleRate: number}>>
List available PortAudio output devices.
Kind: instance method of DeviceManager
Throws:
ErrorIf device listing fails
Set the output device for playback.
Device selection is robust across all PortAudio device types (WASAPI, ASIO, CoreAudio, ALSA, etc.). Throws if device is not found or not output-capable (maxOutputChannels > 0).
Kind: instance method of DeviceManager
Returns: Promise.<object> - Selected device info
Throws:
ErrorIf device is not found or not output-capable
Emits: DeviceManager#event:deviceChange, DeviceManager#event:deviceError
Platform: Windows: WASAPI/ASIO/DirectSound; macOS: CoreAudio; Linux: ALSA/PulseAudio/JACK
Author: zevinDev
| Param | Type | Description |
|---|---|---|
| deviceIndex | number |
Device index |
Get the currently selected output device.
Kind: instance method of DeviceManager
Returns: object | null - Current output device info
Author: zevinDev
Get the default output device.
Kind: instance method of DeviceManager
Returns: Promise.<object> - Default output device info
Throws:
ErrorIf no default device found
Find device by name (partial or exact match).
Kind: instance method of DeviceManager
Returns: Promise.<(object|null)> - Found device or null
Author: zevinDev
| Param | Type | Default | Description |
|---|---|---|---|
| deviceName | string |
Device name to search for | |
| [exactMatch] | boolean |
false |
Whether to require exact match |
Validate device capabilities for playback requirements.
Kind: instance method of DeviceManager
Returns: object - Validation result with capabilities and warnings
Author: zevinDev
| Param | Type | Default | Description |
|---|---|---|---|
| device | object |
Device to validate | |
| requirements | object |
Playback requirements | |
| [requirements.minChannels] | number |
2 |
Minimum required channels |
| [requirements.preferredSampleRate] | number |
Preferred sample rate |
Get PortAudio instance for use by other components.
Kind: instance method of DeviceManager
Returns: Promise.<object> - PortAudio instance
Author: zevinDev
Manages playlist operations including shuffle, repeat, and navigation
Author: zevinDev
- PlaylistManager
- .PlaylistManager
- .loadPlaylist(playlist)
- .setPlaylistShuffle([enable])
- .setPlaylistRepeat(mode)
- .getCurrentTrack() ⇒
string|null - .navigateNext() ⇒
object - .navigatePrevious() ⇒
object - .jumpToTrack(index) ⇒
string|null - .getPlaylistStatus() ⇒
object - .stopPlaylist()
- .clearPlaylist()
- .addTracks(tracks, [insertIndex])
- .removeTracks(indices)
- .isPlaylistActive() ⇒
boolean - .getPlaylistCopy() ⇒
Array.<string>
- .PlaylistManager
PlaylistManager handles playlist state, navigation, and playback modes. Supports shuffle, repeat modes, and efficient playlist operations.
Kind: static class of PlaylistManager
Author: zevinDev
- .PlaylistManager
- .loadPlaylist(playlist)
- .setPlaylistShuffle([enable])
- .setPlaylistRepeat(mode)
- .getCurrentTrack() ⇒
string|null - .navigateNext() ⇒
object - .navigatePrevious() ⇒
object - .jumpToTrack(index) ⇒
string|null - .getPlaylistStatus() ⇒
object - .stopPlaylist()
- .clearPlaylist()
- .addTracks(tracks, [insertIndex])
- .removeTracks(indices)
- .isPlaylistActive() ⇒
boolean - .getPlaylistCopy() ⇒
Array.<string>
Load a new playlist.
Kind: instance method of PlaylistManager
Throws:
ErrorIf playlist is invalid
Author: zevinDev
| Param | Type | Description |
|---|---|---|
| playlist | Array.<string> |
Array of file paths |
Enable or disable shuffle mode for playlists.
Kind: instance method of PlaylistManager
Author: zevinDev
| Param | Type | Default | Description |
|---|---|---|---|
| [enable] | boolean |
true |
Enable shuffle if true |
Set repeat mode for playlists.
Kind: instance method of PlaylistManager
Throws:
ErrorIf invalid repeat mode
Author: zevinDev
| Param | Type | Default | Description |
|---|---|---|---|
| mode | 'off' | 'one' | 'all' |
off |
Repeat mode |
Get the current track from the playlist.
Kind: instance method of PlaylistManager
Returns: string | null - Current track path or null if no playlist active
Author: zevinDev
Navigate to the next track in the playlist. Respects shuffle and repeat settings.
Kind: instance method of PlaylistManager
Returns: object - Navigation result
Author: zevinDev
Navigate to the previous track in the playlist.
Kind: instance method of PlaylistManager
Returns: object - Navigation result
Author: zevinDev
Jump to a specific track index in the playlist.
Kind: instance method of PlaylistManager
Returns: string | null - Track at the specified index
Throws:
ErrorIf index is invalid
Author: zevinDev
| Param | Type | Description |
|---|---|---|
| index | number |
Track index to jump to |
Get playlist status and information.
Kind: instance method of PlaylistManager
Returns: object - Playlist status
Author: zevinDev
Stop playlist playback and clear state.
Kind: instance method of PlaylistManager
Author: zevinDev
Clear playlist without affecting current playback state.
Kind: instance method of PlaylistManager
Author: zevinDev
Add tracks to the current playlist.
Kind: instance method of PlaylistManager
Author: zevinDev
| Param | Type | Description |
|---|---|---|
| tracks | Array.<string> |
Array of track paths to add |
| [insertIndex] | number |
Index to insert at (appends if not specified) |
Remove tracks from the playlist.
Kind: instance method of PlaylistManager
Author: zevinDev
| Param | Type | Description |
|---|---|---|
| indices | Array.<number> |
Array of indices to remove |
Check if the playlist is currently active.
Kind: instance method of PlaylistManager
Returns: boolean - True if playlist is active
Author: zevinDev
Get a copy of the current playlist.
Kind: instance method of PlaylistManager
Returns: Array.<string> - Copy of the playlist
Author: zevinDev
Manages HTTP/HTTPS streaming with buffering, reconnection, and error handling
Author: zevinDev
- StreamManager
- .StreamManager
- .playStream(url, options) ⇒
Promise.<void> - .stopStream()
- .isStreaming() ⇒
boolean - .cleanup()
- .playStream(url, options) ⇒
- .StreamManager
StreamManager handles streaming audio from HTTP/HTTPS URLs. Provides robust buffering, error handling, reconnection, and partial playback support.
Kind: static class of StreamManager
Author: zevinDev
- .StreamManager
- .playStream(url, options) ⇒
Promise.<void> - .stopStream()
- .isStreaming() ⇒
boolean - .cleanup()
- .playStream(url, options) ⇒
Play from a streaming source with robust error handling and reconnection.
Kind: instance method of StreamManager
Throws:
ErrorIf streaming fails after all retries
Author: zevinDev
| Param | Type | Default | Description |
|---|---|---|---|
| url | string |
Streaming source URL (http(s) or file) | |
| options | object |
Streaming options | |
| options.ffmpegPath | string |
Path to ffmpeg binary | |
| options.portaudio | object |
PortAudio instance | |
| options.audioStream | object |
Audio stream for output | |
| options.outputDevice | object |
Output device info | |
| [options.bufferSize] | number |
Buffer size for audio | |
| [options.maxRetries] | number |
5 |
Maximum retry attempts |
| [options.backoffBaseMs] | number |
500 |
Base backoff time in ms |
| [options.bufferSizeBytes] | number |
128*1024 |
Stream buffer size in bytes |
| [options.visualizationCallback] | function |
Callback for PCM data | |
| [options.emitter] | function |
Event emitter for events |
Stop the current stream.
Kind: instance method of StreamManager
Author: zevinDev
Check if currently streaming.
Kind: instance method of StreamManager
Returns: boolean - True if streaming is active
Author: zevinDev
Clean up all streaming resources.
Kind: instance method of StreamManager
Author: zevinDev
Node.js Lossless Audio Player (PortAudio + FFmpeg) - Modular Entry Point
Audio processing and format utilities
Author: zevinDev
- AudioUtils
- .negotiateAudioFormat(trackInfo, deviceInfo, portaudio) ⇒
object - .scalePCMVolume(buffer, volume) ⇒
Float32Array - .mixCrossfade(currentBuffers, nextBuffers, crossfadeFrames, channels, [curve]) ⇒
Array.<Buffer> - .shuffleArray(arr) ⇒
Array - .validateCrossfadeCurve(curve) ⇒
string - .durationToFrames(durationSeconds, sampleRate) ⇒
number - .getFrameSize(channels, [format]) ⇒
number
- .negotiateAudioFormat(trackInfo, deviceInfo, portaudio) ⇒
Negotiate the optimal output format between track and device capabilities. Prefers exact match, then highest supported <= track, else lowest available.
Kind: static method of AudioUtils
Returns: object - Negotiated format and required conversions.
Throws:
ErrorIf portaudio.getDeviceCapabilities is not available.
Author: zevinDev
| Param | Type | Description |
|---|---|---|
| trackInfo | object |
Track info ({ sampleRate, channels, bitDepth }). |
| deviceInfo | object |
Device info ({ index }). |
| portaudio | object |
PortAudio binding instance. |
Example
const fmt = negotiateAudioFormat(track, device, portaudio);Scale PCM float32le buffer by volume (software gain).
Kind: static method of AudioUtils
Returns: Float32Array - Scaled PCM buffer as Float32Array.
Throws:
TypeErrorIf buffer is not Buffer or Float32Array.
Author: zevinDev
| Param | Type | Description |
|---|---|---|
| buffer | Buffer | Float32Array |
PCM buffer (float32le format). |
| volume | number |
Volume multiplier (0.0-1.0). |
Example
const scaled = scalePCMVolume(buf, 0.5);AudioUtils.mixCrossfade(currentBuffers, nextBuffers, crossfadeFrames, channels, [curve]) ⇒ Array.<Buffer>
Mix two PCM buffer arrays for crossfade effects. Supports multiple crossfade curves: linear, logarithmic, exponential.
Kind: static method of AudioUtils
Returns: Array.<Buffer> - Mixed PCM buffers.
Author: zevinDev
| Param | Type | Default | Description |
|---|---|---|---|
| currentBuffers | Array.<Buffer> |
PCM buffers from current track. | |
| nextBuffers | Array.<Buffer> |
PCM buffers from next track. | |
| crossfadeFrames | number |
Number of frames to crossfade. | |
| channels | number |
Number of audio channels. | |
| [curve] | string |
"'linear'" |
Crossfade curve type. |
Example
const mixed = mixCrossfade(curBufs, nextBufs, 1024, 2, 'logarithmic');Fisher-Yates shuffle algorithm for arrays.
Kind: static method of AudioUtils
Returns: Array - Shuffled array (new copy).
Author: zevinDev
| Param | Type | Description |
|---|---|---|
| arr | Array |
Array to shuffle. |
Example
const shuffled = shuffleArray([1,2,3]);Validate crossfade curve parameter.
Kind: static method of AudioUtils
Returns: string - Normalized curve name.
Throws:
ErrorIf curve is invalid.
Author: zevinDev
| Param | Type | Description |
|---|---|---|
| curve | string |
Curve name to validate. |
Example
const c = validateCrossfadeCurve('log');Calculate the number of frames for a given duration and sample rate.
Kind: static method of AudioUtils
Returns: number - Number of frames.
Author: zevinDev
| Param | Type | Description |
|---|---|---|
| durationSeconds | number |
Duration in seconds. |
| sampleRate | number |
Sample rate in Hz. |
Example
const frames = durationToFrames(2.5, 44100);Get frame size in bytes for given format.
Kind: static method of AudioUtils
Returns: number - Frame size in bytes.
Author: zevinDev
| Param | Type | Default | Description |
|---|---|---|---|
| channels | number |
Number of channels. | |
| [format] | string |
"'f32le'" |
Audio format. |
Example
const size = getFrameSize(2, 'f32le');Centralized error handling utilities for the audio player
Author: zevinDev
Centralized error handler for the module. Provides user-friendly error messages and logging capabilities.
Kind: static method of ErrorHandler
Throws:
ErrorOnly rethrows if configured to do so
Author: zevinDev
| Param | Type | Default | Description |
|---|---|---|---|
| error | Error |
The error to handle | |
| [context] | string |
"'Unknown'" |
Context where the error occurred |
| [emitter] | function |
Optional event emitter to emit error events |
Creates user-friendly error messages for common audio player errors.
Kind: static method of ErrorHandler
Returns: string - User-friendly error message
Author: zevinDev
| Param | Type | Description |
|---|---|---|
| error | Error |
The original error |
| context | string |
Context where the error occurred |
Validates common audio player parameters and throws appropriate errors.
Kind: static method of ErrorHandler
Throws:
ErrorIf validation fails
Author: zevinDev
| Param | Type | Description |
|---|---|---|
| params | object |
Parameters to validate |
| params.filePath | string |
Audio file path |
| params.volume | number |
Volume level (0.0-1.0) |
| params.seekPosition | number |
Seek position in seconds |
| params.repeatMode | string |
Repeat mode ('off', 'one', 'all') |
FFmpeg-related utilities for audio processing
Author: zevinDev
- FFmpegUtils
- .locateFFmpeg() ⇒
Promise.<string> - .locateFFprobe() ⇒
Promise.<string> - .buildFFmpegArgs(options) ⇒
Array.<string> - .extractMetadata(filePath, [ffmpegPath]) ⇒
Promise.<Object> - .getAudioInfo(filePath, [ffprobePath]) ⇒
Promise.<Object> - .createFFmpegProcess(ffmpegPath, args, [options]) ⇒
ChildProcess - .killFFmpegProcess(process, [signal]) ⇒
void
- .locateFFmpeg() ⇒
Locate the ffmpeg binary for the current platform.
Kind: static method of FFmpegUtils
Returns: Promise.<string> - Resolves with the path to the ffmpeg binary.
Throws:
ErrorIf ffmpeg binary is not found.
Author: zevinDev
Example
const ffmpegPath = await locateFFmpeg();Locate the ffprobe binary for the current platform.
Kind: static method of FFmpegUtils
Returns: Promise.<string> - Resolves with the path to the ffprobe binary.
Throws:
ErrorIf ffprobe binary is not found.
Author: zevinDev
Example
const ffprobePath = await locateFFprobe();Build FFmpeg arguments for audio conversion/decoding.
Kind: static method of FFmpegUtils
Returns: Array.<string> - FFmpeg arguments array.
Author: zevinDev
| Param | Type | Default | Description |
|---|---|---|---|
| options | object |
Conversion options. | |
| options.input | string |
Input file path or 'pipe:0' for stdin. | |
| [options.output] | string |
"'pipe:1'" |
Output destination or 'pipe:1' for stdout. |
| [options.sampleRate] | number |
44100 |
Target sample rate. |
| [options.channels] | number |
2 |
Target number of channels. |
| [options.format] | string |
"'f32le'" |
Output format. |
| [options.codec] | string |
"'pcm_f32le'" |
Audio codec. |
| [options.seekPosition] | number |
Seek position in seconds. | |
| [options.extra] | Array.<string> |
Extra ffmpeg arguments. |
Example
const args = buildFFmpegArgs({ input: 'track.flac', sampleRate: 48000 });Extract metadata from an audio file using ffmpeg.
Kind: static method of FFmpegUtils
Returns: Promise.<Object> - Resolves with metadata object (title, artist, album, duration, etc.).
Throws:
ErrorIf extraction fails.
Author: zevinDev
| Param | Type | Description |
|---|---|---|
| filePath | string |
Path to the audio file. |
| [ffmpegPath] | string |
Path to ffmpeg binary (auto-detected if not provided). |
Example
const meta = await extractMetadata('track.flac');Get detailed audio stream information from a file.
Kind: static method of FFmpegUtils
Returns: Promise.<Object> - Resolves with audio stream info (sampleRate, channels, bitDepth, duration).
Throws:
ErrorIf analysis fails.
Author: zevinDev
| Param | Type | Description |
|---|---|---|
| filePath | string |
Path to the audio file. |
| [ffprobePath] | string |
Path to ffprobe binary (auto-detected if not provided). |
Example
const info = await getAudioInfo('track.flac');Create and configure an FFmpeg process for audio conversion.
Kind: static method of FFmpegUtils
Returns: ChildProcess - Configured FFmpeg process.
Author: zevinDev
| Param | Type | Description |
|---|---|---|
| ffmpegPath | string |
Path to ffmpeg binary. |
| args | Array.<string> |
FFmpeg arguments. |
| [options] | object |
Spawn options. |
Example
const proc = createFFmpegProcess(ffmpegPath, args);Kill an FFmpeg process safely.
Kind: static method of FFmpegUtils
Author: zevinDev
| Param | Type | Default | Description |
|---|---|---|---|
| process | ChildProcess |
FFmpeg process to kill. | |
| [signal] | string |
"'SIGKILL'" |
Signal to send. |
Example
killFFmpegProcess(proc);getAudioStreamInfo(ffprobePath, filePath) ⇒ Promise.<{sampleRate: number, channels: number, bitDepth: number, duration: number}>
Get audio stream info (sample rate, channels, bit depth, duration) from a file using ffprobe.
Kind: global function
Returns: Promise.<{sampleRate: number, channels: number, bitDepth: number, duration: number}> - Resolves with audio stream info.
Throws:
ErrorIf ffprobe fails or no audio stream info is found, or if JSON parsing fails.
Author: zevinDev
| Param | Type | Description |
|---|---|---|
| ffprobePath | string |
Path to ffprobe executable. |
| filePath | string |
Path to audio file. |
Example
const info = await getAudioStreamInfo('/usr/bin/ffprobe', 'track.flac');
// info = { sampleRate: 44100, channels: 2, bitDepth: 16, duration: 123.45 }