Skip to content

Conversation

@MS-crew
Copy link

@MS-crew MS-crew commented Jan 3, 2026

Description

Describe the changes
This PR restores functional audio playback for the Speaker toy by reintroducing a proper PCM based audio pipeline. The Speaker now actively encodes PCM data using Opus, streams audio in real time, and correctly sends voice packets to clients.

Additionally, this PR introduces a complete Audio API overhaul:
-Seeking Support: Added functionality to jump to specific timestamps in both streamed and preloaded audio.
-Event System: Implemented a full lifecycle event system (OnPlaybackStarted, Paused, Resumed, Stopped, Finished, Looped) for better plugin integration.

High Precision: Switched internal time tracking to double precision to ensure accurate playback timing and seeking.
What is the current behavior? (You can also link to an open issue here)
The current Speaker toy is unable to play any audio. Although audio packets can be sent, no actual playback pipeline exists.

What is the new behavior? (if this is a feature change)
The Speaker can now reliably play audio. It supports streamed and preloaded WAV playback, real-time PCM encoding, looping, targeted or global playback modes, and proper cleanup when playback ends or the toy is removed.

-Playback Pipeline: Real time or Preloaded PCM encoding and streaming.
-WAV Support: Support for both streamed and preloaded WAV playback.
-Advanced Controls: Added Seek(double seconds), CurrentTime, and TotalDuration properties.
-Events: Developers can subscribe to playback events to trigger logic when audio starts, stops, or finishes.
-Flexible Modes: Supports Looping, Targeted (specific players ), Predicate players, or Global playback modes.

Cleanup: Proper resource disposal when playback ends or the toy is removed.

Example usages:
image

2026-01-04.13-03-42.mp4

Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
No. This change restores and extends existing functionality without requiring changes from users.

Other information:


Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentations

Submission checklist

  • I have checked the project can be compiled
  • I have tested my changes and it worked as expected

Patches (if there are any changes related to Harmony patches)

  • I have checked no IL patching errors in the console

Other

  • Still requires more testing

@github-actions github-actions bot added the API label Jan 3, 2026
@MS-crew MS-crew changed the title Speaker toy reborn feat: Speaker toy Api Extend Jan 3, 2026
@MS-crew MS-crew changed the title feat: Speaker toy Api Extend feat: Speaker toy Api Extending Jan 3, 2026
Update PreloadedPcmSource.cs

Update Speaker.cs

Create WavUtility.cs

Update WavStreamSource.cs

Update PreloadedPcmSource.cs

Change default stream parameter to false in PlayWav

Update PlayWav method to default stream to true

Change TargetPlayers from List to HashSet
Update PreloadedPcmSource.cs

Added another constructor for public usages

Update PreloadedPcmSource.cs
@MS-crew MS-crew marked this pull request as draft January 5, 2026 09:16
- Introduced a full Event system to the Speaker class (Started, Finished, Stopped, Paused, Resumed).

- Implemented `Seek()` functionality and added `CurrentTime` / `TotalDuration` properties.

- Utilized `double` precision for all time related calculations to ensure accuracy.

- Updated `WavStreamSource` and `PreloadedPcmSource` to support the new seeking logic.
@MS-crew MS-crew changed the title feat: Speaker toy Api Extending feat: Speaker Toy Api Reborn Jan 5, 2026
@MS-crew MS-crew marked this pull request as ready for review January 5, 2026 10:33
@MS-crew MS-crew changed the title feat: Speaker Toy Api Reborn feat: Speaker Api Reborn Jan 7, 2026
@MS-crew MS-crew changed the title feat: Speaker Api Reborn feat: Speaker Api Jan 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant