Repository navigation
Add announcement role (announcement@v1) - #126
marcelveldt wants to merge 1 commit into
Conversation
Doesn't this defeat the purpose? The nice thing about MA doing the announcement is that all speakers in my living room mute at the same time, play the announcement, and then continue playing. If only 1 player ducks the music, I might still miss it? Also, this proposal made me initially think that announcements would be possible to a second connected client, that is not the one currently streaming the music (as Sonos allows), but that doesn't seem to be the case. All-in-all, I think this proposal could use some more thought about the use cases we want to unlock and if the current proposal covers these. |
Requirements 1, 2, 3 come from experience with this after having this feature in MA for a few years.
Yes that is exactly how it should work - is that not clearly described enough ? EDIT: tightened the wording a bit as I can see where the confusion came from. |
|
But if it's per speaker, it won't work with stereo pairs, or any other set up where a user has 2 speakers set up in the same room. Or if a user targets an area in Home Assistant, it would end up hearing the same announcement in 1 room slightly out of sync. Or you think that HA could be smart to see it's targeting 2 Sendspin players, and get a sync lock before playing the announcement without too much delay? |
It has coordinated start, which is perfect for this usecase |
e9c6545 to
73b5dab
Compare
73b5dab to
d408d24
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved findings affect stream termination, state reporting, audio gain and mute behavior, buffering, and clock synchronization.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Adds the optional announcement@v1 role for client-specific audio announcements with independent streaming, local mixing, and media ducking.
Changes:
- Registers announcement capabilities, message objects, and binary IDs 24–27.
- Defines codec negotiation, timestamps, buffering, lifecycle, volume, ducking, and mute behavior.
- Updates the source template and generated README.
File summaries
| File | Summary and final review findings |
|---|---|
template.md |
Registers and includes the announcement role. No final findings. |
roles/announcement/v1.md |
Defines the announcement protocol. Moderate findings: clarify required client/state reporting (3 votes), absolute volume behavior (2), override_mute gain paths (1), buffer-capacity enforcement (2), and clock synchronization fallback (1). Nit: use muted rather than mute for reported state (1). |
README.md |
Updates the generated specification. No final findings. |
messaging.md |
Moderate finding (1 vote): omitted roles on stream/end can terminate active announcements; clarify media-only termination while retaining explicit announcement abort semantics. |
Review details
Suppressed comments (5)
messaging.md:404
- This makes an omitted
roleslist end announcements, which conflicts with the role's independence guarantee: a mediastream/endis allowed to omitroles, so normal media shutdown can truncate an active announcement and release its ducking. Please define whether media-only ends must enumerate their roles or change the omitted-list semantics, while retaining an explicit way to abort announcements.
- `roles?`: string[] - roles to end streams for ('player', 'artwork', 'visualizer', 'announcement'). If omitted, ends all active streams (an active announcement stream included)
roles/announcement/v1.md:105
- The nominal end is not a reliable playback end for this role: the preceding rules explicitly allow TTS/audio production slower than real time, so output can still be queued after
start_timestamp + sent duration. Becausestream/endcurrently discards remaining buffered audio, a normal completion can truncate the tail; define a graceful drain/EOF behavior separately from abort, or wait for an explicit drained acknowledgement.
- The server knows the announcement's nominal end from its own timeline (`start_timestamp` plus the duration of the audio it has sent). For normal completion it SHOULD NOT send `stream/end` for the announcement role before that time has passed; sending it earlier is the abort path. A client's reported `state: 'idle'` is the precise completion signal.
roles/announcement/v1.md:79
override_mutecannot work with the gain order specified here: applying mute to the mixed output silences both media and announcement, while the last clause requires only the media to remain muted. Define a separate mute path for the media and announcement branches, including its interaction with master volume, so implementations can produce the promised alarm behavior.
3. The client's master volume and mute apply to the mixed output. When the client has the `player` role, these are the player object's [`volume` and `mute`](../player/v1.md#client--server-clientstate-player-object); a client that advertises `announcement` standalone applies its own local volume and mute, if it has them. Announcements are therefore silenced on a muted client, unless the stream sets `override_mute`, in which case the announcement stays audible while the media remains muted.
roles/announcement/v1.md:79
- The player state field is named
muted, notmute(roles/player/v1.md:44-46).muteis the command name, whilemutedis the reported state; usingmutein this reference points implementers to a nonexistent state field.
3. The client's master volume and mute apply to the mixed output. When the client has the `player` role, these are the player object's [`volume` and `mute`](../player/v1.md#client--server-clientstate-player-object); a client that advertises `announcement` standalone applies its own local volume and mute, if it has them. Announcements are therefore silenced on a muted client, unless the stream sets `override_mute`, in which case the announcement stays audible while the media remains muted.
roles/announcement/v1.md:46
- An announcement may be the only active role, but the core
available: truerule only requires clock synchronization for player/source clients. In that valid standalone case the client has no required server-to-local time mapping, so it cannot translatestart_timestampor provide the promised coordinated start. Require clock sync for active announcement clients or define an unsynchronized fallback.
- `start_timestamp`: integer - server clock time in microseconds when announcement output should begin. The client translates it via [clock synchronization](../../messaging.md#clock-synchronization) and starts at that time, or as soon as possible if it has already passed. Targeting several clients with the same `start_timestamp` gives a coordinated multi-speaker start
- Files reviewed: 4/4 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Reworked and rebased on main. Main changes since your review:
Reference client implementation updated to match in Sendspin/sendspin-cpp#101. Marking ready for another look. |
5b3da40 to
244dc8e
Compare
kahrendt
left a comment
There was a problem hiding this comment.
In general, the text in the PR doesn't fit the style and tone of the rest of the spec. It should be able to be condensed down quite a bit.
244dc8e to
6bef956
Compare
|
Did a condensing pass over the whole role file to match the tone of the other roles, and dropped |
6bef956 to
cbb61e5
Compare
<!-- Describe the change and why it is needed. --> This defines how future revisions can add features while preserving compatibility, including when core or role versions must change. It also prepares for #126 with role-specific stream completion while keeping existing media behavior. Clients and servers ignore unknown messages after the initial `server/activate`, while preserving validation and re-handshake restrictions, including messages still arriving with the previous session keys. Optional informational fields defined by the specification can be sent in either direction without additional negotiation if older receivers can ignore them without changing the existing message's meaning. For example, a future informational field in `client/hello` or `server/hello` could use this exception. New message types, binary IDs, and behavior-changing fields still require confirmed support. This does not permit arbitrary fields or extra bytes that break existing binary layouts. Role cleanup covers explicit removal, implicit removal, and version replacement. The server must send `stream/end` for active streams before removal, but need not wait for buffered playback to finish. If removal happens in the first activation after re-handshake, send `stream/end` before starting that handshake. Removal clears the affected output, temporary effects, state, and pending state updates. Potential uses include voice replies, chimes and streamed TTS (#126), new role message types, and companion roles for reporting and controlling native Spotify Connect playback on the device or Bluetooth sources. Multi-server announcements can be added later without a breaking core change through separately negotiated admission and ownership rules that preserve existing peers' behavior. <details> <summary>Multi-server compatibility details</summary> Existing role negotiation can select a future secondary-announcement role while `client/init.version` and `server/init.version` remain `1`. The client and secondary server need updates. Their new rules must preserve compatibility with an unchanged primary. The future role must keep each connection's state and cleanup separate and decline unsupported connections before activation rather than taking over playback. This PR prepares that path but does not implement the role or prove the complete feature. Independent media ducking with unchanged master volume, source-role coexistence, competing announcements, resource use, and audio timing still need a compatibility design. </details> - [x] I accept the [Contributor License Agreement](../blob/main/CONTRIBUTOR-LICENSE-AGREEMENT.md) for this contribution.
|
Any updates or news on this new optional announcement role (announcement@v1) for the Sendspin specification? The questions/comments from balloob + kahrendt about per-client design and multi-speaker sync still looks unsettled? FYI, this has now also been proposed/requested/raised by @kiwipaulrob in this new issue tracker -> #305 That new issue look to raise two additional side points which does not seem to be mentioned that linked pull request:
Both are consequences of having no protocol-level announcement path, and the role in #126 would remove them without the second-server follow-up. |
This comment was marked as low quality.
This comment was marked as low quality.
|
@kiwipaulrob Happy for you to participate in this discussion, not your AI. When discussing this topic, this is a spec. One that can only evolve, never change and be backwards incompatible. Any argument about "Music Assistant doesn't support this today so let's not do it" are moot. We need to develop something that works great. |
|
Noted. I reviewed the comments by my agent so only half agentic. All my points stand. |
<!-- Describe the change and why it is needed. --> Adds an optional `from_timestamp` to `stream/clear`, so a server can replace a player's buffered audio from a point on without waiting for the buffer to play out or leaving a silent gap. ## Why Servers can currently only append audio after everything a player has buffered, or clear the whole buffer and start over after a silent gap. With a large buffer, a changed next track or an announcement either waits for the buffer to play out or cuts to silence first. ## What changes - With `from_timestamp`, players and visualizers drop only buffered data at or after it and keep playing everything before it. The server sends the replacement from that point. - The cut is per chunk: the server picks the timestamp of a chunk it sent, so players never split a chunk. - The cut has to be at least the larger of `min_buffer_ms` and `required_lead_time_ms`, plus `output_delay_ms`, ahead of the message. While a stream runs, `required_lead_time_ms` also has to cover the audio a player has buffered in its audio backend and can't discard. If a cut still lands inside that audio, it plays and the player drops the new audio up to where it ends. - Timestamps after the clear can be earlier than the chunks before it, and the clear doesn't change the stream's format. - Without `from_timestamp`, `stream/clear` works as before. ## Breaking changes - Clients: yes, but it fails softly. Every player and visualizer has to support `from_timestamp`. A client that ignores it does a full clear instead, so it goes silent until the cut and then continues. - Servers: no. A server that never sends `from_timestamp` keeps working unchanged. ## Announcements This is also especially useful for announcements. The separate announcement role in #126 puts most of the work on the client: a second stream, mixing and ducking. With this change most of it moves to the server, which mixes the announcement into the music itself, so it's likely simpler for clients. It covers most of what #126 does, and grouped players stay in sync. To play the announcement louder than the music, the server turns the music down further by the amount it raises the volume, and leaves a short gap of turned-down music before and after the clip. It raises the volume during the gap before the clip and restores it during the gap after. The gap is needed because volume commands aren't timed to the audio. This only works on players that accept volume commands. It also adds a short delay before the announcement, and other controllers see the volume go up and back down. A separate announcement role would still be needed for: - the client knowing an announcement is playing, for example to stop only the announcement locally - announcing on devices without the player role, or on an idle speaker without it showing as playing - a second server announcing while another server plays music ### How a server could play an announcement 1. Pick a start time for the announcement. It has to be far enough ahead that each target player has a chunk start between its minimum lead and that time. 2. Send each target player a `stream/clear` with `from_timestamp` set to that chunk start. 3. Resend the music from the cut. Keep it unchanged up to the start time, then fade it down and mix in the clip, leaving a short gap of turned-down music before and after the clip. If the player's current format differs from the replacement's, send a `stream/start` first. 4. To make the clip louder than the music, turn the music down further by the amount you raise the volume. Send the volume command during the gap before the clip and restore it during the gap after, so the music's level stays the same when the command lands. 5. After the clip, raise the music back to its normal level and keep streaming on the same timeline. Players that weren't targeted keep playing unchanged. ## Trade-offs - A cut that drops an in-place format change, like a buffered next track at another sample rate, doesn't roll the format back. The server has to send another `stream/start` before a replacement in the old format. I went with this since rolling back would need every client to keep a format history. - With Opus, the player's decoder has already decoded the dropped packets, so the first replacement packet can cause a brief artifact at the join. Clients shouldn't need a change for this. A server can avoid it by keeping its encoder state at the cut. FLAC and PCM are not affected. - I considered a separate `required_clear_lead_time_ms` field, so a player with a slow cold start doesn't delay every announcement by its startup time. The clients below report fixed values between 150 and 500 ms, so I don't think it's worth one more field. - A player with a deep audio backend buffer, like an ESPHome speaker, reports a higher `required_lead_time_ms` while playing. In a group, it pushes the cut later for every player. I made this a requirement on `required_lead_time_ms` instead of a new field, since a lead measured from a `stream/clear` on a running pipeline already includes waiting for that audio. ## Client effort I had Claude check three clients, so take this with a grain of salt. It looks moderate in all of them. Each already keeps a server timestamp on every buffered chunk, so dropping the tail itself is easy. The main work is dropping only the chunks at or after the cut that are still being decoded or queued when the clear arrives, since today a clear drops all of them. | Client | Rough size | Where buffered audio sits | Main work | `required_lead_time_ms` today | |---|---|---|---|---| | sendspin-js | 100 to 150 lines | Web Audio sources scheduled up to 20 s ahead, each can be stopped | In-flight decodes are dropped by a counter every clear bumps, needs a check against the cut | fixed 250 ms, may be close to Bluetooth output latency | | sendspin-cpp | 150 to 250 lines | Encoded chunks in the inbound ring | Drop the tail and release its buffer quota as soon as the message arrives | 150 ms, covers the example sink, on ESPHome it also has to cover the speaker buffers it can't clear (Sendspin/sendspin-cpp#55) | | sendspin-rs | 200 to 400 lines | Decoded audio in a sorted queue, tail drop is one `retain` | The counter that fences off old audio needs a cut-aware version, touches public traits | 500 ms, plenty | Sizes are rough estimates and exclude tests. Related: - #126 - [x] I accept the [Contributor License Agreement](../blob/main/CONTRIBUTOR-LICENSE-AGREEMENT.md) for this contribution.
|
Marking this as draft for now, since #336 merged and a server can now mix an announcement into the music itself, which covers most use cases and keeps grouped players in sync. I can see that a separate role is still useful for a second server announcing. But this PR needs to be reworked first since it doesn't handle multiple servers. |
|
I still stand by my points from Oct 9, re-stated in my own words: I run Music Assistant against a moOde sendspin client. Announcements today are stop-and-resume — playing, idle, playing per clip. Per-client stream with local ducking fixes that. It also removes two workarounds that only exist because there is no protocol-level announcement path: the ESPHome-manufacturer filter in MA's relay and the MAC-as-client_id correlation. On sync scope: balloob's stereo-pair concern is real for music, but for announcements (doorbell, TTS, alarm) coordinated start is enough. That is the common case. On second-server announce: I agree with maximmaxim345 that a separate role is still useful there. Happy to see this reworked to handle multiple servers. Happy to help however I can. Thanx for all great work with SendSpin. |
Adds a new optional role,
announcement@v1, that lets a client play short client-specific audio (voice-assistant replies, doorbell chimes, alerts) as its own stream, mixed over or independent of media playback, with the media ducked locally on the client.Why
Announcements are currently outside the protocol, so servers fake them. Music Assistant today snapshots player state, ungroups, stops the stream, plays the clip as normal media, then restores everything. For ESPHome speakers that is a step backwards: their firmware already has a first-class dual-pipeline model (media keeps playing, the announcement mixes over it, the media ducks) that Sendspin can't reach.
This role announces on any speaker without touching a playing group's timeline. The media stream keeps flowing to every group member, and each targeted client ducks its own output and mixes the announcement over it.
What's in it
announcement@v1_supportobject (its announcement formats and a dedicated buffer capacity).stream/startcarrying the codec params, a singlestart_timestamp, the duck level and ramp, and an optional absolutevolume.start_timestamp; if TTS is slow the stream simply stretches.stream/endfinishes or aborts it.start_timestampfor a coordinated start. Sample-accurate cross-client sync of the announcement audio itself is out of scope for v1.messaging.mdandtemplate.mdfor the role registration, binary-ID allocation, and message objects; addsroles/announcement/v1.md.Landing directly as
announcement@v1(pre-1.0 spec), not staged as a draft revision.Out of scope (possible follow-up)
Open questions
media_duck_dbdefaults to 0 (off) andduck_ramp_msto 100 ms. Input from the ESPHome side welcome.Companion client reference implementation: Sendspin/sendspin-cpp#101.