sonos-announcePlay audio on Sonos with intelligent state restoration - pauses streaming, skips Line-In/TV/Bluetooth, resumes everything.
Install via ClawdBot CLI:
clawdbot install clawdianova/sonos-announcePlay audio files on Sonos speakers with intelligent state restoration.
This skill handles playback only - audio generation (TTS, ElevenLabs, etc.) is separate.
import sys
import os
sys.path.insert(0, '/path/to/sonos-announce')
from sonos_core import announce
# Play audio and restore previous state
# Assumes audio is in default media_dir (~/.local/share/openclaw/media/outbound)
result = announce('my_audio.mp3')
pip install soco
Requirements:
python3 - Python 3ffprobe - Part of ffmpeg, for audio duration detectionsoco - Python Sonos libraryannounce(audio_file_path, wait_for_audio=True, media_dir=None)
| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| audio_file_path | str | required | Filename (if using media_dir) or full path to audio file |
| wait_for_audio | bool | True | Wait for audio to finish playing before returning |
| media_dir | str | None | Directory where audio file is located (HTTP server will serve from here) |
{
'coordinators': 2,
'states': {
'192.168.1.120': {
'uri': 'x-sonos-spotify:spotify%3atrack%3a...',
'position': '0:01:23',
'queue_position': 5,
'was_playing': True,
'is_external': False,
'transport_state': 'PLAYING',
'speaker_name': 'Bedroom'
}
}
}
from sonos_core import announce
# File served from default media_dir
result = announce('announcement.mp3')
from sonos_core import announce
# Full path to audio file
result = announce(
'my_audio.mp3',
media_dir='/home/user/audio/announcements'
)
from sonos_core import announce
# Uses directory of file as media_dir
result = announce('/full/path/to/audio.mp3')
Configure the HTTP server for streaming to Sonos:
| Variable | Default | Description |
|----------|---------|-------------|
| SONOS_HTTP_HOST | auto-detected | LAN IP address (auto-detected) |
| SONOS_HTTP_PORT | 8888 | HTTP server port |
# Set before running (optional)
export SONOS_HTTP_HOST=192.168.1.100 # Override auto-detected IP
export SONOS_HTTP_PORT=8888 # Override port
# Or set in code before importing
import os
os.environ['SONOS_HTTP_HOST'] = '192.168.1.100'
from sonos_core import announce
announce('audio.mp3')
| Platform | Status | Notes |
|----------|--------|-------|
| macOS | β Supported | Full support |
| Linux | β Supported | Full support |
| Windows | β
Supported | Uses taskkill and start /b |
The module automatically detects your platform and uses appropriate commands for:
The module intelligently restores previous playback state:
| Source Type | Behavior |
|------------|----------|
| Spotify Track | Resumed at exact position (seek) |
| Spotify Playlist | Resumed at exact position (seek) |
| Spotify Radio | Resumed from start (no seek) |
| Internet Radio | Resumed from start (no seek) |
| Line-In | Re-connected to Line-In input |
| TV/HDMI | Re-connected to TV audio |
| Bluetooth | Re-connected to Bluetooth |
| Paused content | Left paused |
Some streaming services don't support seeking to a specific position:
The module automatically detects these and handles accordingly.
Automatically detects inputs that cannot be paused:
x-rincon:RINCON_* - Line-Inx-rincon-stream:RINCON_* - Line-In stream x-sonos-htastream:* - TV/HDMI (Sonos Home Theater)x-sonos-vanished:* - Vanished devicex-rincon-bt:* - Bluetoothfrom sonos_core import announce
SOUNDS = {
'airhorn': '/path/to/sounds/airhorn.mp3',
'rimshot': '/path/to/sounds/rimshot.mp3',
'victory': '/path/to/sounds/victory.mp3',
}
def play_sound(name):
"""Play a sound effect."""
if name in SOUNDS:
announce(SOUNDS[name])
else:
print(f"Unknown sound: {name}")
| Issue | Solution |
|-------|----------|
| No speakers found | Ensure on same network as Sonos speakers |
| Resume not working | Check speakers were playing (not paused) before announcement |
| HTTP server failed | Check port 8888 is available, or set SONOS_HTTP_PORT |
| Module import error | Run: pip install soco |
| Duration detection fails | Ensure ffprobe is installed (part of ffmpeg) |
sonos_core.py - Main module with announce() functionSKILL.md - This documentationGenerated Mar 1, 2026
Homeowners use this skill to play custom audio alerts, such as doorbell rings or weather warnings, on Sonos speakers throughout their house. It intelligently pauses music or streaming services and resumes them after the announcement, ensuring minimal disruption to ongoing audio.
Retailers integrate this skill to broadcast promotional messages or sound effects over Sonos speakers in-store. It can play jingles or announcements during sales events, automatically restoring background music or radio streams afterward to maintain ambiance.
Businesses deploy this skill for office-wide announcements, such as meeting reminders or emergency alerts, using Sonos speakers in common areas. It handles various audio sources like streaming playlists, ensuring seamless resumption of background audio post-announcement.
Hotels and resorts utilize this skill to play welcome messages or event notifications in guest rooms and public spaces via Sonos systems. It manages different input sources like Bluetooth or TV audio, restoring them to provide uninterrupted guest experiences.
Event organizers employ this skill for live sound effects, such as applause or fanfares, during conferences or parties using Sonos speakers. It pauses any playing media, plays the effect, and resumes the original audio to enhance event dynamics without manual intervention.
Offer a cloud-based platform where users can upload and schedule announcements, with API access to this skill for automated playback on Sonos. Revenue is generated through monthly subscriptions based on usage tiers, such as number of announcements or speaker groups.
Provide consulting and development services to integrate this skill into existing smart home or business systems, such as IoT platforms or CRM software. Revenue comes from one-time project fees or ongoing support contracts for customization and maintenance.
Bundle this skill with pre-configured Sonos speaker setups for specific industries, like retail or hospitality, offering turnkey solutions for audio announcements. Revenue is generated through hardware sales and optional software licensing fees for advanced features.
π¬ Integration Tip
Ensure ffprobe is installed for audio duration detection and set SONOS_HTTP_PORT to an available port to avoid server conflicts.
Terminal Spotify playback/search via spogo (preferred) or spotify_player.
Search GIF providers with CLI/TUI, download results, and extract stills/sheets.
Download videos from YouTube, Bilibili, Twitter, and thousands of other sites using yt-dlp. Use when the user provides a video URL and wants to download it, extract audio (MP3), download subtitles, or select video quality. Triggers on phrases like "δΈθ½½θ§ι’", "download video", "yt-dlp", "YouTube", "Bη«", "ζι³", "ζει³ι’", "extract audio".
Search and add movies to Radarr. Supports collections, search-on-add option.
Control Spotify playback on macOS. Play/pause, skip tracks, control volume, play artists/albums/playlists. Use when a user asks to play music, control Spotify, change songs, or adjust Spotify volume.
Search and add TV shows to Sonarr. Supports monitor options, search-on-add.