Skip to content

feat: add audio engine and Web Audio streaming - #50

Merged
zijipia merged 55 commits into
mainfrom
AudioEngine
Oct 29, 2026
Merged

zijipia merged 55 commits into
mainfrom
AudioEngine

Conversation

@zijipia

@zijipia zijipia commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add a configurable audio processing engine and output backend interfaces.
  • Add Discord voice and WebSocket audio output backends.
  • Add a browser Web Audio client with PCM decoding and playback buffering.
  • Add a session-aware example gateway and backend demo for browser playback.
  • Expand audio backend documentation and setup guides.
  • Add tests for audio processing, output backends, playback session transitions, and gateway session routing.
  • Update CI workflow and repository guidance.

Verification

  • The branch comparison contains 14 commits ahead of main.
  • Tests have not been executed as part of creating this PR; please verify the test suite and clean-clone Quick Start in CI or locally.

Review notes

  • The example backend currently demonstrates a single configured player by default, even though the gateway supports session-scoped routing.
  • Preserve the currently working browser playback path while reviewing lifecycle, reconnect, and multi-session behavior.

zijipia and others added 14 commits October 10, 2026 00:07
I kept the change incremental and backward-compatible:

Added the DSP engine abstraction and PCM pipeline in AudioProcessingEngine.ts
Hooked it into resource creation in PlaybackController.ts
Kept the default behavior on the legacy @discordjs/voice path unless audioProcessing.enabled is explicitly turned on
Included a safe fallback to the older stream path if DSP processing throws
I fixed the root cause in AudioProcessingEngine.ts: the resolver now respects the DSP enabled state before deciding the stream type.

Behavior now:

when DSP is disabled, it preserves the caller fallback type
when raw PCM is actually being emitted, it returns StreamType.Raw
when encoded output is used, it keeps the original stream type instead of mislabeling the resource
…ining Discord Voice as the default.

Architecture and behavior
Added the typed backend contract in AudioOutputBackend.ts: explicit encoded/PCM formats, stream ownership, capabilities, readiness, lifecycle, cancellation, events, and unsupported-operation errors.
Added DiscordVoiceOutputBackend.ts to adapt Discord resource creation, player lifecycle, volume, and raw-PCM requirements. Float32 PCM is explicitly converted to signed 16-bit little-endian at this boundary.
Kept PlaybackController.ts as the Discord-facing compatibility controller; it delegates selected output operations without moving crossfade, recovery, session, or queue policy into the adapter.
Decoupled AudioProcessingEngine.ts from Discord runtime resources and declared/enforced processed PCM dimensions. Removed the unsafe fallback that could replay a partially consumed source as encoded bytes; failed or cancelled processing now cleans up owned streams.
Propagated cancellation through PlaybackStartController.ts and ResourceRefreshController.ts. Exported the new API through index.ts.
Added fake-backend and Discord-adapter coverage in audio_output_backend.test.js, expanded DSP coverage in audio_processing_engine.test.js, and documented current dependencies and future Web-backend requirements in AUDIO_OUTPUT_BACKENDS.md.
Compatibility remains Discord-first: existing AudioResource-facing APIs remain available, Discord is still selected by default, and audioProcessing changes DSP options rather than output backend selection. The future Web transport is not implemented. Remaining Discord-coupled surfaces and Web transport concerns are recorded in the architecture document.
- Changed stopPlayback method signatures to return Promise<void> in various controllers.
- Updated calls to stopPlayback to use await for proper asynchronous handling.
- Modified PreloadController to handle playback state changes asynchronously.
- Enhanced error handling in audio output backend tests to ensure proper lifecycle management.
- Improved documentation on audio output backend selection and lifecycle management.
- Added error reporting to the PlaybackSkipController, PlaybackStartController, and PlaybackTrackEndController to capture and log stream errors.
- Improved error handling in the PlaybackOrchestrator to ensure that errors during track end and playback stop are properly reported.
- Updated tests to cover new error handling scenarios, including stop failures and remote stop actions.
- Enhanced the FakeAudioOutputBackend to simulate various failure conditions for more robust testing.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Created a new client package for handling WebSocket PCM streams with AudioWorklet.
- Implemented tests for audio configuration validation and PCM frame decoding.
- Added a backend example with WebSocket support for audio streaming.
- Included HTML and JavaScript files for a web client interface to connect to the audio stream.
- Established a gateway for managing publisher and listener connections with authentication.
- Implemented tests for the gateway to ensure proper handling of audio configuration and PCM frames.
… session management; enhance gateway and client with session handling
@vercel

vercel Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
zi-player Ready Ready Preview Oct 29, 2026 2:33pm UTC

@qodo-code-review

Copy link
Copy Markdown

ⓘ Qodo reviews are paused because your trial has ended. Ask your workspace admin to add credits to resume reviews. Manage billing

This change removes the demo token requirement from the browser WebSocket gateway, makes listener auth optional, and enforces loopback-only local deployment. The example backend now supports per-player session IDs, player-state queries, and playback control routing for pause/resume/seek/volume/filter actions.

It also updates the browser client and TypeScript types to allow optional `token` values, adds tests for the new gateway and volume behavior, and implements backend-level PCM volume scaling in `WebSocketAudioOutputBackend` while reporting the capability as supported.
This change makes preload requests complete gracefully when no track is ready, adds per-session listener count notifications and idle player cleanup in the backend gateway, and ensures audio pipelines accept Node Readable streams. It also updates websocket backend capability behavior and regression tests covering disabled-preload, listener-count, and volume handling.
Playback now treats search results as a playlist only when the result includes playlist metadata; otherwise it queues just the first match. The public docs and examples were updated to reflect this behavior, and the backend demo client got a richer player UI with track cards, queue counts, and metadata panels. Regression tests cover the playlist-vs-single-track selection logic.
This patch fixes stale pause/resume checks on facade players, keeps custom audio backends reporting the backend status, and makes the backend example push player state over SSE instead of polling. It also adds `preferYoutubei` ordering to YouTube stream fallback selection, updates the docs/example usage, and covers the behavior with regression tests.
This commit hardens the DSP/PCM path by guarding invalid samples, enforcing maxBufferBytes before output chunks escape the pipeline, and cleaning up async iterators safely. It also updates the public documentation to clarify the encoded-input-only DSP contract, browser/WebSocket PCM requirements, and custom backend usage.
Centralize plugin registration in PluginController while keeping player-specific plugins, stream caches, and search state isolated. Route player context through search and stream resolution, add regression coverage, and bump package versions.
Preserve requester objects on tracks while passing requester IDs to search plugins. Add asynchronous, player-scoped extension activation and Bus subscription cleanup, update extensions and documentation, and cover the new behavior with regression tests.
Move controller state into namespaced player.data maps, with cleanup on player teardown. Allow managed players to change their public ID without interrupting playback by preserving their internal routing identity. Wire heartbeat tracking to managed players and document the new APIs.
Support guild objects when changing or destroying players, emit player ID change notifications, and preserve routing aliases for actions and forwarding. Reject ID changes on destroyed players and cover lifecycle and forwarding cleanup.
Add YouTube lookup fallbacks, preserve stream metadata on exports, and make lyrics search resilient to request failures. Update core dependency handling and speed up test builds while improving lifecycle and audio regression coverage.
Update the plugin package's development version and core dependency, use TrackRequester for SoundCloud requests, and route YouTube debug logging through the manager's tracer.
Filter plugins by canHandle, prioritize TTS tracks for tts: queries, and route playback only when the selected track is TTS. Prevent SoundCloud from claiming unsupported queries and add routing regression tests.
Add configurable Web Audio analyser support, frequency-band and bass-energy helpers, and documentation and tests for browser visualizers. Bump the client package to 1.0.3.
Add per-player FIFO TTS playback with skip/stop handling and safe music restoration. Improve the browser client for Electron and Tauri with autoplay recovery, configurable worklet URLs, and socket cleanup; document desktop integration and add regression tests.
Prevent concurrent TTS requests from invalidating each other's results, and preserve an unlocked AudioContext when connecting or reconnecting. Add EventTarget-compatible TypeScript overloads and regression tests.
Remove the general-purpose FFmpeg processing engine and its public configuration and exports. Normal playback now feeds streams directly to audio resources, while FilterController retains FFmpeg for filtering and non-seekable seeks. Update documentation and replace engine-focused tests with playback pipeline and filter lifecycle coverage.
@zijipia
zijipia merged commit 35dba8b into main Oct 29, 2026
4 of 6 checks passed
@zijipia
zijipia deleted the AudioEngine branch October 29, 2026 14:35

This branch was successfully deployed

1 active deployment
Preview — a9f48b92 Deployed Oct 29, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant