Sonos 音乐点播
Overview
这个 skill 面向中文用户,用来沉淀可复用的 Sonos 点播工作流。
当前已验证兼容的音乐服务:
This skill assumes:
- - Sonos devices are reachable on the local network
- the
sonos CLI is installed and available in INLINECODE1 - Sonos App has a working linked music-service authorization for the target service
- service availability may vary by region and by the user's linked Sonos music services
This skill avoids machine-specific hardcoded paths by resolving from:
- - INLINECODE2
- INLINECODE3
- INLINECODE4
- INLINECODE5
- INLINECODE6
- INLINECODE7
Default behavior should remain simple:
- - workspace defaults to the current OpenClaw workspace inferred from the skill location
- venv defaults to INLINECODE8
- wrappers default to
./scripts/sonos_netease_play.sh and ./scripts/sonos_qq_play.sh under the workspace - playback scripts default to
./scripts/sonos_netease_play.py and ./scripts/sonos_qq_play.py under the workspace
Quick Start
Preferred simple install:
CODEBLOCK0
Manual flow if needed:
CODEBLOCK1
If the check fails, run bootstrap:
CODEBLOCK2
Then use the standard playback entrypoints, for example:
CODEBLOCK3
Workflow
1. Prefer one-command install
Prefer scripts/install.sh when:
- - using the skill for the first time
- after migration or system reinstall
- handing the skill to another environment
2. Check environment
Run scripts/check_env.sh when:
- - debugging a broken environment
- validating an installation result
3. Bootstrap if needed
Run scripts/bootstrap_env.sh when:
- -
soco is missing - the Sonos Python venv does not exist
- either playback wrapper is missing or not executable
Bootstrap will:
- - create the Sonos Python venv if missing
- install
soco if missing - verify both playback wrappers and scripts exist
Bootstrap does not install the sonos CLI. If sonos is missing, install or restore it separately.
4. Play through the standard wrappers
Do not call the Python playback files with system python3.
Prefer the wrappers because they pin the correct Python venv and avoid interpreter drift.
Important implementation contract
Preserve metadata by playing from queue
When implementing or patching the playback logic, do not replace queue playback with a direct play_uri(...) rewrite.
Correct pattern:
- - search via INLINECODE22
- convert the selected result into a Sonos-accepted object with INLINECODE23
- INLINECODE24
- INLINECODE25
This preserves Sonos App metadata such as:
- - title
- artist
- album
- album art
Do not trust search titles alone
Search results through Sonos may contain:
- - same-title tracks by different artists
- live / piano / cover / female / child / sentimental variants
- results whose final queue metadata differs from the plain search title
Prefer a two-stage selection strategy:
- 1. title-based initial filtering
- queue-metadata-based rescoring using actual Sonos metadata
QQ音乐-specific note
INLINECODE26 currently supports searching QQ音乐 via sonos smapi search --service 'QQ音乐', but its --open flow still behaves like a Spotify-only path and does not directly play QQ search results.
For QQ音乐, use the validated queue-based SoCo path instead of sonos smapi search --open.
Troubleshooting
Can search but cannot play
First suspect linked service authorization state in Sonos App.
A reliable recovery path is usually:
- - re-add or re-authorize the music service in Sonos App
QQ音乐 auth page opens but does not complete in CLI
This is likely an incompatibility in the current CLI auth/open flow rather than a proof that QQ音乐 itself is unavailable in Sonos.
If Sonos App already has a working QQ音乐 binding and sonos smapi search --service 'QQ音乐' returns results, prefer the SoCo queue-based playback path.
Plays but metadata is blank
First inspect whether the playback path regressed to play_uri(...).
Still chooses the wrong version
Inspect the actual queue metadata returned by Sonos. If the search source itself does not return the desired original version, this is a source-quality limitation, not necessarily a scoring bug.
Release Checklist
Before publishing or distributing this skill, verify:
- -
scripts/check_env.sh returns ready=yes in a representative environment - INLINECODE34 can create the venv and install
soco when missing - a real 网易云 playback command reaches INLINECODE36
- a real QQ音乐 playback command reaches INLINECODE37
- INLINECODE38 is non-empty after playback starts
- the documented prerequisites match reality for the target environment
Resources
scripts/
- one-command installer that runs bootstrap and validation, then prints example playback commands
- portable environment checker using environment-variable-based path resolution
- portable bootstrap script for the Sonos Python venv and
soco, and verifies both playback entrypoints exist
Sonos 音乐点播
概述
本技能面向中文用户,用于沉淀可复用的 Sonos 点播工作流。
当前已验证兼容的音乐服务:
本技能假设:
- - Sonos 设备在本地网络中可访问
- sonos CLI 已安装并在 PATH 中可用
- Sonos App 已为目标服务配置有效的关联音乐服务授权
- 服务可用性可能因地区及用户关联的 Sonos 音乐服务而异
本技能通过以下环境变量解析路径,避免使用机器特定的硬编码路径:
- - OPENCLAWWORKSPACEDIR
- OPENCLAWSONOSVENV
- OPENCLAWSONOSNETEASEWRAPPER
- OPENCLAWSONOSQQWRAPPER
- OPENCLAWSONOSNETEASESCRIPT
- OPENCLAWSONOSQQSCRIPT
默认行为应保持简单:
- - 工作区默认根据技能位置推断为当前 OpenClaw 工作区
- venv 默认为 $HOME/.openclaw/venvs/soco-sonos
- 包装脚本默认为工作区下的 ./scripts/sonosneteaseplay.sh 和 ./scripts/sonosqqplay.sh
- 播放脚本默认为工作区下的 ./scripts/sonosneteaseplay.py 和 ./scripts/sonosqqplay.py
快速开始
推荐简单安装方式:
bash
./skills/sonos-music-playback-market/scripts/install.sh
如需手动操作:
bash
./skills/sonos-music-playback-market/scripts/check_env.sh
如果检查失败,运行引导脚本:
bash
./skills/sonos-music-playback-market/scripts/bootstrap_env.sh
然后使用标准播放入口,例如:
bash
./scripts/sonosneteaseplay.sh --room Living Room 至少还有你
./scripts/sonosqqplay.sh --room Living Room 稻香
工作流程
1. 优先使用一键安装
在以下情况优先使用 scripts/install.sh:
- - 首次使用本技能时
- 迁移或系统重装后
- 将技能部署到其他环境时
2. 检查环境
在以下情况运行 scripts/check_env.sh:
3. 必要时进行引导
在以下情况运行 scripts/bootstrap_env.sh:
- - soco 缺失时
- Sonos Python venv 不存在时
- 任一播放包装脚本缺失或不可执行时
引导脚本将执行以下操作:
- - 如果缺失则创建 Sonos Python venv
- 如果缺失则安装 soco
- 验证两个播放包装脚本和脚本文件是否存在
引导脚本不会安装 sonos CLI。如果 sonos 缺失,请单独安装或恢复。
4. 通过标准包装脚本播放
不要使用系统 python3 直接调用 Python 播放文件。
建议使用包装脚本,因为它们会锁定正确的 Python venv,避免解释器漂移。
重要实现约定
通过队列播放保留元数据
在实现或修补播放逻辑时,不要用直接的 play_uri(...) 重写替代队列播放。
正确模式:
- - 通过 sonos smapi search 搜索
- 使用 SoCo MusicService(...) 将选中的结果转换为 Sonos 可接受的对象
- addtoqueue(...)
- playfromqueue(...)
这样可以保留 Sonos App 中的元数据,例如:
不要仅依赖搜索标题
通过 Sonos 搜索的结果可能包含:
- - 不同艺术家的同名曲目
- 现场版/钢琴版/翻唱版/女声版/儿童版/伤感版等变体
- 最终队列元数据与纯搜索标题不一致的结果
建议采用两阶段选择策略:
- 1. 基于标题的初步筛选
- 基于队列元数据并使用实际 Sonos 元数据进行重新评分
QQ音乐特别说明
sonoscli 目前支持通过 sonos smapi search --service QQ音乐 搜索 QQ音乐,但其 --open 流程仍仅适用于 Spotify 路径,无法直接播放 QQ音乐搜索结果。
对于 QQ音乐,请使用经过验证的基于队列的 SoCo 路径,而非 sonos smapi search --open。
故障排除
可以搜索但无法播放
首先怀疑 Sonos App 中的关联服务授权状态。
通常可靠的恢复路径是:
- - 在 Sonos App 中重新添加或重新授权音乐服务
QQ音乐认证页面打开但在 CLI 中未完成
这很可能是当前 CLI 认证/打开流程的不兼容问题,而非 QQ音乐本身在 Sonos 中不可用。
如果 Sonos App 已有有效的 QQ音乐绑定,且 sonos smapi search --service QQ音乐 能返回结果,建议使用基于 SoCo 队列的播放路径。
可以播放但元数据为空
首先检查播放路径是否回退到了 play_uri(...)。
仍然选择了错误的版本
检查 Sonos 返回的实际队列元数据。如果搜索源本身未返回所需的原始版本,这是源质量问题,不一定是评分错误。
发布检查清单
在发布或分发本技能前,请验证:
- - scripts/checkenv.sh 在代表性环境中返回 ready=yes
- scripts/bootstrapenv.sh 能在缺失时创建 venv 并安装 soco
- 真实的网易云音乐播放命令能达到 PLAYING 状态
- 真实的 QQ音乐播放命令能达到 PLAYING 状态
- 播放开始后 nowPlaying.title 不为空
- 文档中列出的前提条件与目标环境实际情况一致
资源
scripts/
- 一键安装程序,运行引导和验证,然后打印示例播放命令
- 可移植的环境检查器,使用基于环境变量的路径解析
- - scripts/bootstrap_env.sh
- 可移植的引导脚本,用于 Sonos Python venv 和 soco,并验证两个播放入口点是否存在