MOSS: a small, mostly 3D-printed litter-picking rover. Cleaner streets, one maker at a time.
Python
sounds: the rover's nonverbal voice, a synthesized sound pack (60 cues, 20 families, original) played through the robot user's audio session on confirmed events (stack up, contact, recovery after a stall, explore order, exploration done, battery low and critical with hysteresis); MOSS_SOUNDS / MOSS_SOUND_VOLUME / MOSS_SOUND_SINK; cold bench
metrox0607fb5ec149
diff --git a/assets/sounds/battery_critical_01.wav b/assets/sounds/battery_critical_01.wavnew file mode 100644index 0000000..7065145Binary files /dev/null and b/assets/sounds/battery_critical_01.wav differdiff --git a/assets/sounds/battery_critical_02.wav b/assets/sounds/battery_critical_02.wavnew file mode 100644index 0000000..c83bca1Binary files /dev/null and b/assets/sounds/battery_critical_02.wav differdiff --git a/assets/sounds/battery_critical_03.wav b/assets/sounds/battery_critical_03.wavnew file mode 100644index 0000000..d7a5bb6Binary files /dev/null and b/assets/sounds/battery_critical_03.wav differdiff --git a/assets/sounds/battery_low_01.wav b/assets/sounds/battery_low_01.wavnew file mode 100644index 0000000..1d9d7c0Binary files /dev/null and b/assets/sounds/battery_low_01.wav differdiff --git a/assets/sounds/battery_low_02.wav b/assets/sounds/battery_low_02.wavnew file mode 100644index 0000000..bf06ad2Binary files /dev/null and b/assets/sounds/battery_low_02.wav differdiff --git a/assets/sounds/battery_low_03.wav b/assets/sounds/battery_low_03.wavnew file mode 100644index 0000000..eaa4b97Binary files /dev/null and b/assets/sounds/battery_low_03.wav differdiff --git a/assets/sounds/bin_drop_01.wav b/assets/sounds/bin_drop_01.wavnew file mode 100644index 0000000..e0439f5Binary files /dev/null and b/assets/sounds/bin_drop_01.wav differdiff --git a/assets/sounds/bin_drop_02.wav b/assets/sounds/bin_drop_02.wavnew file mode 100644index 0000000..7b72031Binary files /dev/null and b/assets/sounds/bin_drop_02.wav differdiff --git a/assets/sounds/bin_drop_03.wav b/assets/sounds/bin_drop_03.wavnew file mode 100644index 0000000..8769535Binary files /dev/null and b/assets/sounds/bin_drop_03.wav differdiff --git a/assets/sounds/boot_ready_01.wav b/assets/sounds/boot_ready_01.wavnew file mode 100644index 0000000..6c99e05Binary files /dev/null and b/assets/sounds/boot_ready_01.wav differdiff --git a/assets/sounds/boot_ready_02.wav b/assets/sounds/boot_ready_02.wavnew file mode 100644index 0000000..ae68ac5Binary files /dev/null and b/assets/sounds/boot_ready_02.wav differdiff --git a/assets/sounds/boot_ready_03.wav b/assets/sounds/boot_ready_03.wavnew file mode 100644index 0000000..7325dd1Binary files /dev/null and b/assets/sounds/boot_ready_03.wav differdiff --git a/assets/sounds/bump_surprise_01.wav b/assets/sounds/bump_surprise_01.wavnew file mode 100644index 0000000..875d81bBinary files /dev/null and b/assets/sounds/bump_surprise_01.wav differdiff --git a/assets/sounds/bump_surprise_02.wav b/assets/sounds/bump_surprise_02.wavnew file mode 100644index 0000000..2f0f775Binary files /dev/null and b/assets/sounds/bump_surprise_02.wav differdiff --git a/assets/sounds/bump_surprise_03.wav b/assets/sounds/bump_surprise_03.wavnew file mode 100644index 0000000..0debfb8Binary files /dev/null and b/assets/sounds/bump_surprise_03.wav differdiff --git a/assets/sounds/config.json b/assets/sounds/config.jsonnew file mode 100644index 0000000..8a84e6d--- /dev/null+++ b/assets/sounds/config.json@@ -0,0 +1,12 @@+{+ "volume": 0.65,+ "global_gap_s": 2.0,+ "mute": false,+ "personality": false,+ "backend": "auto",+ "target": null,+ "queue_limit": 16,+ "event_id_window_s": 60,+ "dedup_limit": 512,+ "events": {}+}diff --git a/assets/sounds/curious_01.wav b/assets/sounds/curious_01.wavnew file mode 100644index 0000000..1d6f05bBinary files /dev/null and b/assets/sounds/curious_01.wav differdiff --git a/assets/sounds/curious_02.wav b/assets/sounds/curious_02.wavnew file mode 100644index 0000000..ce24633Binary files /dev/null and b/assets/sounds/curious_02.wav differdiff --git a/assets/sounds/curious_03.wav b/assets/sounds/curious_03.wavnew file mode 100644index 0000000..1a81c48Binary files /dev/null and b/assets/sounds/curious_03.wav differdiff --git a/assets/sounds/hello_01.wav b/assets/sounds/hello_01.wavnew file mode 100644index 0000000..ce05b94Binary files /dev/null and b/assets/sounds/hello_01.wav differdiff --git a/assets/sounds/hello_02.wav b/assets/sounds/hello_02.wavnew file mode 100644index 0000000..a2babb8Binary files /dev/null and b/assets/sounds/hello_02.wav differdiff --git a/assets/sounds/hello_03.wav b/assets/sounds/hello_03.wavnew file mode 100644index 0000000..cf74e2bBinary files /dev/null and b/assets/sounds/hello_03.wav differdiff --git a/assets/sounds/manifest.json b/assets/sounds/manifest.jsonnew file mode 100644index 0000000..228974b--- /dev/null+++ b/assets/sounds/manifest.json@@ -0,0 +1,756 @@+{+ "pack": "MOSS robot sounds",+ "version": "1.0.0",+ "voice": "Original nonverbal playful 8-bit robot cues, synthesized for MOSS",+ "format": {+ "sample_rate": 44100,+ "channels": 1,+ "sample_width_bytes": 2+ },+ "asset_count": 60,+ "event_count": 20,+ "events": {+ "boot_ready": {+ "description": "System ready after startup",+ "category": "system",+ "priority": 30,+ "cooldown_s": 15,+ "enabled": true,+ "ttl_s": 1.5,+ "variants": [+ "boot_ready_01",+ "boot_ready_02",+ "boot_ready_03"+ ]+ },+ "hello": {+ "description": "Explicit user greeting / demo",+ "category": "personality",+ "priority": 20,+ "cooldown_s": 20,+ "enabled": false,+ "ttl_s": 1.5,+ "variants": [+ "hello_01",+ "hello_02",+ "hello_03"+ ]+ },+ "curious": {+ "description": "Optional exploration personality cue",+ "category": "personality",+ "priority": 10,+ "cooldown_s": 45,+ "enabled": false,+ "ttl_s": 1.5,+ "variants": [+ "curious_01",+ "curious_02",+ "curious_03"+ ]+ },+ "obstacle_noticed": {+ "description": "Obstacle causes a new avoidance action",+ "category": "recovery",+ "priority": 35,+ "cooldown_s": 12,+ "enabled": false,+ "ttl_s": 1.5,+ "variants": [+ "obstacle_noticed_01",+ "obstacle_noticed_02",+ "obstacle_noticed_03"+ ]+ },+ "bump_surprise": {+ "description": "Confirmed contact or recovery trigger",+ "category": "recovery",+ "priority": 50,+ "cooldown_s": 8,+ "enabled": true,+ "ttl_s": 1.5,+ "variants": [+ "bump_surprise_01",+ "bump_surprise_02",+ "bump_surprise_03"+ ]+ },+ "repositioning": {+ "description": "Optional intermediate recovery state",+ "category": "recovery",+ "priority": 25,+ "cooldown_s": 12,+ "enabled": false,+ "ttl_s": 1.5,+ "variants": [+ "repositioning_01",+ "repositioning_02",+ "repositioning_03"+ ]+ },+ "recovery_success": {+ "description": "Recovery completed and progress resumed",+ "category": "recovery",+ "priority": 45,+ "cooldown_s": 8,+ "enabled": true,+ "ttl_s": 1.5,+ "variants": [+ "recovery_success_01",+ "recovery_success_02",+ "recovery_success_03"+ ]+ },+ "stuck": {+ "description": "Recovery failed / human intervention requested",+ "category": "recovery",+ "priority": 65,+ "cooldown_s": 20,+ "enabled": true,+ "ttl_s": 1.5,+ "variants": [+ "stuck_01",+ "stuck_02",+ "stuck_03"+ ]+ },+ "resume": {+ "description": "Explicit resume from pause",+ "category": "system",+ "priority": 35,+ "cooldown_s": 5,+ "enabled": true,+ "ttl_s": 1.5,+ "variants": [+ "resume_01",+ "resume_02",+ "resume_03"+ ]+ },+ "target_spotted": {+ "description": "New litter target selected",+ "category": "pickup",+ "priority": 25,+ "cooldown_s": 10,+ "enabled": false,+ "ttl_s": 1.5,+ "variants": [+ "target_spotted_01",+ "target_spotted_02",+ "target_spotted_03"+ ]+ },+ "pickup_attempt": {+ "description": "Optional beginning of one grasp attempt",+ "category": "pickup",+ "priority": 25,+ "cooldown_s": 10,+ "enabled": false,+ "ttl_s": 1.5,+ "variants": [+ "pickup_attempt_01",+ "pickup_attempt_02",+ "pickup_attempt_03"+ ]+ },+ "pickup_success": {+ "description": "Pickup confirmed, not only commanded",+ "category": "pickup",+ "priority": 55,+ "cooldown_s": 6,+ "enabled": true,+ "ttl_s": 1.5,+ "variants": [+ "pickup_success_01",+ "pickup_success_02",+ "pickup_success_03"+ ]+ },+ "pickup_missed": {+ "description": "Grasp failure confirmed",+ "category": "pickup",+ "priority": 40,+ "cooldown_s": 10,+ "enabled": true,+ "ttl_s": 1.5,+ "variants": [+ "pickup_missed_01",+ "pickup_missed_02",+ "pickup_missed_03"+ ]+ },+ "bin_drop": {+ "description": "Confirmed release into bin",+ "category": "pickup",+ "priority": 45,+ "cooldown_s": 6,+ "enabled": false,+ "ttl_s": 1.5,+ "variants": [+ "bin_drop_01",+ "bin_drop_02",+ "bin_drop_03"+ ]+ },+ "mission_complete": {+ "description": "Task/mission actually completed",+ "category": "system",+ "priority": 60,+ "cooldown_s": 20,+ "enabled": true,+ "ttl_s": 1.5,+ "variants": [+ "mission_complete_01",+ "mission_complete_02",+ "mission_complete_03"+ ]+ },+ "battery_low": {+ "description": "Battery crossed low threshold with hysteresis",+ "category": "battery",+ "priority": 80,+ "cooldown_s": 90,+ "enabled": true,+ "ttl_s": 3.0,+ "variants": [+ "battery_low_01",+ "battery_low_02",+ "battery_low_03"+ ]+ },+ "battery_critical": {+ "description": "Battery crossed critical threshold",+ "category": "battery",+ "priority": 95,+ "cooldown_s": 30,+ "enabled": true,+ "ttl_s": 3.0,+ "variants": [+ "battery_critical_01",+ "battery_critical_02",+ "battery_critical_03"+ ]+ },+ "teleop_connected": {+ "description": "Control session became connected",+ "category": "connection",+ "priority": 35,+ "cooldown_s": 8,+ "enabled": true,+ "ttl_s": 1.5,+ "variants": [+ "teleop_connected_01",+ "teleop_connected_02",+ "teleop_connected_03"+ ]+ },+ "teleop_disconnected": {+ "description": "Control session became disconnected",+ "category": "connection",+ "priority": 75,+ "cooldown_s": 15,+ "enabled": true,+ "ttl_s": 3.0,+ "variants": [+ "teleop_disconnected_01",+ "teleop_disconnected_02",+ "teleop_disconnected_03"+ ]+ },+ "sleep": {+ "description": "Going idle or shutting down, if audio is still available",+ "category": "system",+ "priority": 30,+ "cooldown_s": 20,+ "enabled": false,+ "ttl_s": 1.5,+ "variants": [+ "sleep_01",+ "sleep_02",+ "sleep_03"+ ]+ }+ },+ "assets": {+ "boot_ready_01": {+ "path": "boot_ready_01.wav",+ "event": "boot_ready",+ "variant": 1,+ "duration_s": 0.695,+ "peak_dbfs": -12.04,+ "rms_dbfs": -20.81+ },+ "boot_ready_02": {+ "path": "boot_ready_02.wav",+ "event": "boot_ready",+ "variant": 2,+ "duration_s": 0.67,+ "peak_dbfs": -12.04,+ "rms_dbfs": -20.85+ },+ "boot_ready_03": {+ "path": "boot_ready_03.wav",+ "event": "boot_ready",+ "variant": 3,+ "duration_s": 0.735,+ "peak_dbfs": -12.04,+ "rms_dbfs": -20.99+ },+ "hello_01": {+ "path": "hello_01.wav",+ "event": "hello",+ "variant": 1,+ "duration_s": 0.545,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.06+ },+ "hello_02": {+ "path": "hello_02.wav",+ "event": "hello",+ "variant": 2,+ "duration_s": 0.435,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.02+ },+ "hello_03": {+ "path": "hello_03.wav",+ "event": "hello",+ "variant": 3,+ "duration_s": 0.545,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.32+ },+ "curious_01": {+ "path": "curious_01.wav",+ "event": "curious",+ "variant": 1,+ "duration_s": 0.595,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.56+ },+ "curious_02": {+ "path": "curious_02.wav",+ "event": "curious",+ "variant": 2,+ "duration_s": 0.515,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.69+ },+ "curious_03": {+ "path": "curious_03.wav",+ "event": "curious",+ "variant": 3,+ "duration_s": 0.65,+ "peak_dbfs": -12.04,+ "rms_dbfs": -22.11+ },+ "obstacle_noticed_01": {+ "path": "obstacle_noticed_01.wav",+ "event": "obstacle_noticed",+ "variant": 1,+ "duration_s": 0.37,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.77+ },+ "obstacle_noticed_02": {+ "path": "obstacle_noticed_02.wav",+ "event": "obstacle_noticed",+ "variant": 2,+ "duration_s": 0.38,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.57+ },+ "obstacle_noticed_03": {+ "path": "obstacle_noticed_03.wav",+ "event": "obstacle_noticed",+ "variant": 3,+ "duration_s": 0.39,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.94+ },+ "bump_surprise_01": {+ "path": "bump_surprise_01.wav",+ "event": "bump_surprise",+ "variant": 1,+ "duration_s": 0.51,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.13+ },+ "bump_surprise_02": {+ "path": "bump_surprise_02.wav",+ "event": "bump_surprise",+ "variant": 2,+ "duration_s": 0.54,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.46+ },+ "bump_surprise_03": {+ "path": "bump_surprise_03.wav",+ "event": "bump_surprise",+ "variant": 3,+ "duration_s": 0.425,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.44+ },+ "repositioning_01": {+ "path": "repositioning_01.wav",+ "event": "repositioning",+ "variant": 1,+ "duration_s": 0.63,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.74+ },+ "repositioning_02": {+ "path": "repositioning_02.wav",+ "event": "repositioning",+ "variant": 2,+ "duration_s": 0.575,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.61+ },+ "repositioning_03": {+ "path": "repositioning_03.wav",+ "event": "repositioning",+ "variant": 3,+ "duration_s": 0.625,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.88+ },+ "recovery_success_01": {+ "path": "recovery_success_01.wav",+ "event": "recovery_success",+ "variant": 1,+ "duration_s": 0.455,+ "peak_dbfs": -12.04,+ "rms_dbfs": -20.94+ },+ "recovery_success_02": {+ "path": "recovery_success_02.wav",+ "event": "recovery_success",+ "variant": 2,+ "duration_s": 0.445,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.2+ },+ "recovery_success_03": {+ "path": "recovery_success_03.wav",+ "event": "recovery_success",+ "variant": 3,+ "duration_s": 0.535,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.3+ },+ "stuck_01": {+ "path": "stuck_01.wav",+ "event": "stuck",+ "variant": 1,+ "duration_s": 0.685,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.18+ },+ "stuck_02": {+ "path": "stuck_02.wav",+ "event": "stuck",+ "variant": 2,+ "duration_s": 0.755,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.44+ },+ "stuck_03": {+ "path": "stuck_03.wav",+ "event": "stuck",+ "variant": 3,+ "duration_s": 0.695,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.25+ },+ "resume_01": {+ "path": "resume_01.wav",+ "event": "resume",+ "variant": 1,+ "duration_s": 0.495,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.32+ },+ "resume_02": {+ "path": "resume_02.wav",+ "event": "resume",+ "variant": 2,+ "duration_s": 0.45,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.0+ },+ "resume_03": {+ "path": "resume_03.wav",+ "event": "resume",+ "variant": 3,+ "duration_s": 0.47,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.27+ },+ "target_spotted_01": {+ "path": "target_spotted_01.wav",+ "event": "target_spotted",+ "variant": 1,+ "duration_s": 0.41,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.49+ },+ "target_spotted_02": {+ "path": "target_spotted_02.wav",+ "event": "target_spotted",+ "variant": 2,+ "duration_s": 0.45,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.65+ },+ "target_spotted_03": {+ "path": "target_spotted_03.wav",+ "event": "target_spotted",+ "variant": 3,+ "duration_s": 0.515,+ "peak_dbfs": -12.04,+ "rms_dbfs": -22.12+ },+ "pickup_attempt_01": {+ "path": "pickup_attempt_01.wav",+ "event": "pickup_attempt",+ "variant": 1,+ "duration_s": 0.495,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.16+ },+ "pickup_attempt_02": {+ "path": "pickup_attempt_02.wav",+ "event": "pickup_attempt",+ "variant": 2,+ "duration_s": 0.465,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.22+ },+ "pickup_attempt_03": {+ "path": "pickup_attempt_03.wav",+ "event": "pickup_attempt",+ "variant": 3,+ "duration_s": 0.59,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.33+ },+ "pickup_success_01": {+ "path": "pickup_success_01.wav",+ "event": "pickup_success",+ "variant": 1,+ "duration_s": 0.615,+ "peak_dbfs": -12.04,+ "rms_dbfs": -20.7+ },+ "pickup_success_02": {+ "path": "pickup_success_02.wav",+ "event": "pickup_success",+ "variant": 2,+ "duration_s": 0.635,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.03+ },+ "pickup_success_03": {+ "path": "pickup_success_03.wav",+ "event": "pickup_success",+ "variant": 3,+ "duration_s": 0.645,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.27+ },+ "pickup_missed_01": {+ "path": "pickup_missed_01.wav",+ "event": "pickup_missed",+ "variant": 1,+ "duration_s": 0.555,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.24+ },+ "pickup_missed_02": {+ "path": "pickup_missed_02.wav",+ "event": "pickup_missed",+ "variant": 2,+ "duration_s": 0.62,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.64+ },+ "pickup_missed_03": {+ "path": "pickup_missed_03.wav",+ "event": "pickup_missed",+ "variant": 3,+ "duration_s": 0.635,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.51+ },+ "bin_drop_01": {+ "path": "bin_drop_01.wav",+ "event": "bin_drop",+ "variant": 1,+ "duration_s": 0.435,+ "peak_dbfs": -12.04,+ "rms_dbfs": -22.0+ },+ "bin_drop_02": {+ "path": "bin_drop_02.wav",+ "event": "bin_drop",+ "variant": 2,+ "duration_s": 0.42,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.24+ },+ "bin_drop_03": {+ "path": "bin_drop_03.wav",+ "event": "bin_drop",+ "variant": 3,+ "duration_s": 0.54,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.74+ },+ "mission_complete_01": {+ "path": "mission_complete_01.wav",+ "event": "mission_complete",+ "variant": 1,+ "duration_s": 0.935,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.06+ },+ "mission_complete_02": {+ "path": "mission_complete_02.wav",+ "event": "mission_complete",+ "variant": 2,+ "duration_s": 0.905,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.11+ },+ "mission_complete_03": {+ "path": "mission_complete_03.wav",+ "event": "mission_complete",+ "variant": 3,+ "duration_s": 0.905,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.27+ },+ "battery_low_01": {+ "path": "battery_low_01.wav",+ "event": "battery_low",+ "variant": 1,+ "duration_s": 0.645,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.05+ },+ "battery_low_02": {+ "path": "battery_low_02.wav",+ "event": "battery_low",+ "variant": 2,+ "duration_s": 0.575,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.45+ },+ "battery_low_03": {+ "path": "battery_low_03.wav",+ "event": "battery_low",+ "variant": 3,+ "duration_s": 0.725,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.65+ },+ "battery_critical_01": {+ "path": "battery_critical_01.wav",+ "event": "battery_critical",+ "variant": 1,+ "duration_s": 0.805,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.77+ },+ "battery_critical_02": {+ "path": "battery_critical_02.wav",+ "event": "battery_critical",+ "variant": 2,+ "duration_s": 0.75,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.81+ },+ "battery_critical_03": {+ "path": "battery_critical_03.wav",+ "event": "battery_critical",+ "variant": 3,+ "duration_s": 0.825,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.68+ },+ "teleop_connected_01": {+ "path": "teleop_connected_01.wav",+ "event": "teleop_connected",+ "variant": 1,+ "duration_s": 0.445,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.57+ },+ "teleop_connected_02": {+ "path": "teleop_connected_02.wav",+ "event": "teleop_connected",+ "variant": 2,+ "duration_s": 0.435,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.09+ },+ "teleop_connected_03": {+ "path": "teleop_connected_03.wav",+ "event": "teleop_connected",+ "variant": 3,+ "duration_s": 0.445,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.45+ },+ "teleop_disconnected_01": {+ "path": "teleop_disconnected_01.wav",+ "event": "teleop_disconnected",+ "variant": 1,+ "duration_s": 0.505,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.48+ },+ "teleop_disconnected_02": {+ "path": "teleop_disconnected_02.wav",+ "event": "teleop_disconnected",+ "variant": 2,+ "duration_s": 0.49,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.28+ },+ "teleop_disconnected_03": {+ "path": "teleop_disconnected_03.wav",+ "event": "teleop_disconnected",+ "variant": 3,+ "duration_s": 0.505,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.49+ },+ "sleep_01": {+ "path": "sleep_01.wav",+ "event": "sleep",+ "variant": 1,+ "duration_s": 0.725,+ "peak_dbfs": -12.04,+ "rms_dbfs": -20.73+ },+ "sleep_02": {+ "path": "sleep_02.wav",+ "event": "sleep",+ "variant": 2,+ "duration_s": 0.695,+ "peak_dbfs": -12.04,+ "rms_dbfs": -20.94+ },+ "sleep_03": {+ "path": "sleep_03.wav",+ "event": "sleep",+ "variant": 3,+ "duration_s": 0.805,+ "peak_dbfs": -12.04,+ "rms_dbfs": -21.37+ }+ }+}diff --git a/assets/sounds/mission_complete_01.wav b/assets/sounds/mission_complete_01.wavnew file mode 100644index 0000000..fdcdcadBinary files /dev/null and b/assets/sounds/mission_complete_01.wav differdiff --git a/assets/sounds/mission_complete_02.wav b/assets/sounds/mission_complete_02.wavnew file mode 100644index 0000000..13bfdd1Binary files /dev/null and b/assets/sounds/mission_complete_02.wav differdiff --git a/assets/sounds/mission_complete_03.wav b/assets/sounds/mission_complete_03.wavnew file mode 100644index 0000000..9f033edBinary files /dev/null and b/assets/sounds/mission_complete_03.wav differdiff --git a/assets/sounds/obstacle_noticed_01.wav b/assets/sounds/obstacle_noticed_01.wavnew file mode 100644index 0000000..a845af1Binary files /dev/null and b/assets/sounds/obstacle_noticed_01.wav differdiff --git a/assets/sounds/obstacle_noticed_02.wav b/assets/sounds/obstacle_noticed_02.wavnew file mode 100644index 0000000..83c390dBinary files /dev/null and b/assets/sounds/obstacle_noticed_02.wav differdiff --git a/assets/sounds/obstacle_noticed_03.wav b/assets/sounds/obstacle_noticed_03.wavnew file mode 100644index 0000000..af38734Binary files /dev/null and b/assets/sounds/obstacle_noticed_03.wav differdiff --git a/assets/sounds/pickup_attempt_01.wav b/assets/sounds/pickup_attempt_01.wavnew file mode 100644index 0000000..efd24fdBinary files /dev/null and b/assets/sounds/pickup_attempt_01.wav differdiff --git a/assets/sounds/pickup_attempt_02.wav b/assets/sounds/pickup_attempt_02.wavnew file mode 100644index 0000000..030cc1aBinary files /dev/null and b/assets/sounds/pickup_attempt_02.wav differdiff --git a/assets/sounds/pickup_attempt_03.wav b/assets/sounds/pickup_attempt_03.wavnew file mode 100644index 0000000..d92192bBinary files /dev/null and b/assets/sounds/pickup_attempt_03.wav differdiff --git a/assets/sounds/pickup_missed_01.wav b/assets/sounds/pickup_missed_01.wavnew file mode 100644index 0000000..8a1a72eBinary files /dev/null and b/assets/sounds/pickup_missed_01.wav differdiff --git a/assets/sounds/pickup_missed_02.wav b/assets/sounds/pickup_missed_02.wavnew file mode 100644index 0000000..2242433Binary files /dev/null and b/assets/sounds/pickup_missed_02.wav differdiff --git a/assets/sounds/pickup_missed_03.wav b/assets/sounds/pickup_missed_03.wavnew file mode 100644index 0000000..7cb4e72Binary files /dev/null and b/assets/sounds/pickup_missed_03.wav differdiff --git a/assets/sounds/pickup_success_01.wav b/assets/sounds/pickup_success_01.wavnew file mode 100644index 0000000..cc05451Binary files /dev/null and b/assets/sounds/pickup_success_01.wav differdiff --git a/assets/sounds/pickup_success_02.wav b/assets/sounds/pickup_success_02.wavnew file mode 100644index 0000000..aafe5c8Binary files /dev/null and b/assets/sounds/pickup_success_02.wav differdiff --git a/assets/sounds/pickup_success_03.wav b/assets/sounds/pickup_success_03.wavnew file mode 100644index 0000000..18edc08Binary files /dev/null and b/assets/sounds/pickup_success_03.wav differdiff --git a/assets/sounds/recovery_success_01.wav b/assets/sounds/recovery_success_01.wavnew file mode 100644index 0000000..e79f253Binary files /dev/null and b/assets/sounds/recovery_success_01.wav differdiff --git a/assets/sounds/recovery_success_02.wav b/assets/sounds/recovery_success_02.wavnew file mode 100644index 0000000..ddbeb61Binary files /dev/null and b/assets/sounds/recovery_success_02.wav differdiff --git a/assets/sounds/recovery_success_03.wav b/assets/sounds/recovery_success_03.wavnew file mode 100644index 0000000..6754d23Binary files /dev/null and b/assets/sounds/recovery_success_03.wav differdiff --git a/assets/sounds/repositioning_01.wav b/assets/sounds/repositioning_01.wavnew file mode 100644index 0000000..7142c6bBinary files /dev/null and b/assets/sounds/repositioning_01.wav differdiff --git a/assets/sounds/repositioning_02.wav b/assets/sounds/repositioning_02.wavnew file mode 100644index 0000000..fcbe197Binary files /dev/null and b/assets/sounds/repositioning_02.wav differdiff --git a/assets/sounds/repositioning_03.wav b/assets/sounds/repositioning_03.wavnew file mode 100644index 0000000..d8f8011Binary files /dev/null and b/assets/sounds/repositioning_03.wav differdiff --git a/assets/sounds/resume_01.wav b/assets/sounds/resume_01.wavnew file mode 100644index 0000000..c626e34Binary files /dev/null and b/assets/sounds/resume_01.wav differdiff --git a/assets/sounds/resume_02.wav b/assets/sounds/resume_02.wavnew file mode 100644index 0000000..d9a37dfBinary files /dev/null and b/assets/sounds/resume_02.wav differdiff --git a/assets/sounds/resume_03.wav b/assets/sounds/resume_03.wavnew file mode 100644index 0000000..20a411aBinary files /dev/null and b/assets/sounds/resume_03.wav differdiff --git a/assets/sounds/sleep_01.wav b/assets/sounds/sleep_01.wavnew file mode 100644index 0000000..304292aBinary files /dev/null and b/assets/sounds/sleep_01.wav differdiff --git a/assets/sounds/sleep_02.wav b/assets/sounds/sleep_02.wavnew file mode 100644index 0000000..e14ac20Binary files /dev/null and b/assets/sounds/sleep_02.wav differdiff --git a/assets/sounds/sleep_03.wav b/assets/sounds/sleep_03.wavnew file mode 100644index 0000000..232ea74Binary files /dev/null and b/assets/sounds/sleep_03.wav differdiff --git a/assets/sounds/stuck_01.wav b/assets/sounds/stuck_01.wavnew file mode 100644index 0000000..f6bfdabBinary files /dev/null and b/assets/sounds/stuck_01.wav differdiff --git a/assets/sounds/stuck_02.wav b/assets/sounds/stuck_02.wavnew file mode 100644index 0000000..7749367Binary files /dev/null and b/assets/sounds/stuck_02.wav differdiff --git a/assets/sounds/stuck_03.wav b/assets/sounds/stuck_03.wavnew file mode 100644index 0000000..9a6e7d9Binary files /dev/null and b/assets/sounds/stuck_03.wav differdiff --git a/assets/sounds/target_spotted_01.wav b/assets/sounds/target_spotted_01.wavnew file mode 100644index 0000000..6f7ddf4Binary files /dev/null and b/assets/sounds/target_spotted_01.wav differdiff --git a/assets/sounds/target_spotted_02.wav b/assets/sounds/target_spotted_02.wavnew file mode 100644index 0000000..0e235bcBinary files /dev/null and b/assets/sounds/target_spotted_02.wav differdiff --git a/assets/sounds/target_spotted_03.wav b/assets/sounds/target_spotted_03.wavnew file mode 100644index 0000000..1cf1923Binary files /dev/null and b/assets/sounds/target_spotted_03.wav differdiff --git a/assets/sounds/teleop_connected_01.wav b/assets/sounds/teleop_connected_01.wavnew file mode 100644index 0000000..d5d6f94Binary files /dev/null and b/assets/sounds/teleop_connected_01.wav differdiff --git a/assets/sounds/teleop_connected_02.wav b/assets/sounds/teleop_connected_02.wavnew file mode 100644index 0000000..c73cbabBinary files /dev/null and b/assets/sounds/teleop_connected_02.wav differdiff --git a/assets/sounds/teleop_connected_03.wav b/assets/sounds/teleop_connected_03.wavnew file mode 100644index 0000000..d93b664Binary files /dev/null and b/assets/sounds/teleop_connected_03.wav differdiff --git a/assets/sounds/teleop_disconnected_01.wav b/assets/sounds/teleop_disconnected_01.wavnew file mode 100644index 0000000..227731dBinary files /dev/null and b/assets/sounds/teleop_disconnected_01.wav differdiff --git a/assets/sounds/teleop_disconnected_02.wav b/assets/sounds/teleop_disconnected_02.wavnew file mode 100644index 0000000..6f28720Binary files /dev/null and b/assets/sounds/teleop_disconnected_02.wav differdiff --git a/assets/sounds/teleop_disconnected_03.wav b/assets/sounds/teleop_disconnected_03.wavnew file mode 100644index 0000000..18b3261Binary files /dev/null and b/assets/sounds/teleop_disconnected_03.wav differdiff --git a/benches/bench_moss_sounds_cold.py b/benches/bench_moss_sounds_cold.pynew file mode 100644index 0000000..e26f7a7--- /dev/null+++ b/benches/bench_moss_sounds_cold.py@@ -0,0 +1,133 @@+"""Cold bench: moss_dimos/sounds.py, the sound pack on the stack's events.++Known input -> known output: a bump plays bump_surprise; a stall followed by+motion plays recovery_success once; the battery crossing the low threshold for+long enough plays battery_low once, with hysteresis; the vendored pack has+every file its manifest names; the player in dry-run mode queues what the+module hands it. No audio device, no subprocess.++Run: PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=. python3 benches/bench_moss_sounds_cold.py+"""+import asyncio+import json+import os+import sys+import time+from pathlib import Path++ROOT = Path(__file__).resolve().parent.parent+sys.path.insert(0, str(ROOT))++OK = KO = 0+++def check(cond, label, detail=""):+ global OK, KO+ if cond:+ OK += 1+ else:+ KO += 1+ print((" OK " if cond else " KO ") + label + (f" - {detail}" if detail and not cond else ""))+++print("A. the vendored pack: manifest, files, player in dry run")+from moss_dimos.sound_pack.player import MossSoundPlayer, playback_command # noqa: E402++ASSETS = ROOT / "assets" / "sounds"+manifest = json.loads((ASSETS / "manifest.json").read_text())+missing = [k for k, a in manifest["assets"].items() if not (ASSETS / a["path"]).exists()]+check(len(manifest["assets"]) == 60 and not missing, f"60 assets named and present ({len(manifest['assets'])} named, missing {missing[:3]})")+check(len(manifest["events"]) == 20 and all(len(e["variants"]) == 3 for e in manifest["events"].values()),+ "20 event families, three variants each")+check("date" not in manifest and "hardware_context" not in manifest, "the manifest carries no date and no workshop context")+cmd = playback_command(ASSETS / "boot_ready_01.wav", backend="paplay", target="bt_sink", volume=0.5) if __import__("shutil").which("paplay") else None+check(cmd is None or (cmd[0] == "paplay" and "--device=bt_sink" in cmd and cmd[-1].endswith("boot_ready_01.wav")),+ f"paplay command names the sink and the file: {cmd}")+player = MossSoundPlayer(root=ASSETS, dry_run=True)+check(set(player.rules) == set(manifest["events"]), "the player loads every family from the manifest")+check(player.emit("bump_surprise") is True, "emit(bump_surprise) is queued")+check(player.emit("bump_surprise") is False, "the same family again inside its cooldown is suppressed")+check(player.emit("no_such_family") is False, "an unknown family is refused")+player.wait_idle(timeout=3)+status = player.drain_status()+check(any(s.get("event") == "bump_surprise" for s in status), f"dry run reports the cue: {[s.get('state') for s in status][:4]}")+player.set_mute(True)+check(player.emit("resume") is False, "muted: nothing queued")+player.set_mute(False)+player.close()++print("B. EventMapper: the stack's events -> families")+from moss_dimos.sounds import (BATTERY_CRITICAL_MV, BATTERY_LOW_CLEAR_MV, BATTERY_LOW_MV, BATTERY_SAMPLES, # noqa: E402+ RECOVERY_MIN_TICKS, RECOVERY_WINDOW_S, EventMapper, MossSounds, sound_volume, sounds_enabled)++m = EventMapper()+check(m.on_bump(True) == ["bump_surprise"] and m.on_bump(False) == [], "bump True -> bump_surprise, False -> nothing")+check(m.on_explore_cmd(True) == ["resume"] and m.on_explore_done(True) == ["mission_complete"], "explore_cmd -> resume, explore_done -> mission_complete")+t0 = 1000.0+tel = lambda stalls, ticks, mv=11800: {"stall_count": stalls, "ticks": list(ticks), "bus_mV": mv} # noqa: E731+check(m.on_telemetry(tel(0, (100, 100)), t0) == [], "no stall, healthy battery -> nothing")+check(m.on_telemetry(tel(1, (100, 100)), t0 + 1) == [], "a new stall is remembered, nothing plays (the bump cue comes from the bus)")+check(m.on_telemetry(tel(1, (120, 110)), t0 + 2) == [], "a few ticks after the stall are not a recovery")+check(m.on_telemetry(tel(1, (100 + RECOVERY_MIN_TICKS, 100)), t0 + 3) == ["recovery_success"], "the tracks move again -> recovery_success")+check(m.on_telemetry(tel(1, (100 + 3 * RECOVERY_MIN_TICKS, 100)), t0 + 4) == [], "...once")+check(m.on_telemetry(tel(2, (500, 500)), t0 + 10) == [] and m.on_telemetry(tel(2, (500 + RECOVERY_MIN_TICKS, 500)), t0 + 10 + RECOVERY_WINDOW_S + 1) == [],+ "motion after the window is not a recovery")+b = EventMapper()+low = BATTERY_LOW_MV - 100+res = []+for i in range(BATTERY_SAMPLES):+ res += b.on_telemetry({"bus_mV": low}, t0 + i)+check(res == ["battery_low"], f"battery_low after {BATTERY_SAMPLES} lines below {BATTERY_LOW_MV} mV, once: {res}")+check(b.on_telemetry({"bus_mV": low}, t0 + 9) == [], "...and not again while it stays low")+check(b.on_telemetry({"bus_mV": BATTERY_LOW_MV + 100}, t0 + 10) == [], "a sag recovery between low and clear changes nothing")+check(b._battery_state == "low", "still low below the clear level")+check(b.on_telemetry({"bus_mV": BATTERY_LOW_CLEAR_MV + 50}, t0 + 11) == [] and b._battery_state == "ok", "above the clear level -> ok again (hysteresis)")+c = EventMapper()+seq = []+for i in range(BATTERY_SAMPLES):+ seq += c.on_telemetry({"bus_mV": BATTERY_CRITICAL_MV - 50}, t0 + i)+check(seq == ["battery_low", "battery_critical"], f"straight to critical: low then critical, each once: {seq}")+check(c.on_telemetry({"bus_mV": 0}, t0 + 20) == [] and c.on_telemetry({"bus_mV": None}, t0 + 21) == [], "no reading -> nothing")+check(sound_volume(0.65, {"MOSS_SOUND_VOLUME": "0.3"}) == 0.3 and sound_volume(0.65, {}) == 0.65+ and sound_volume(0.65, {"MOSS_SOUND_VOLUME": "2"}) == 1.0 and sound_volume(0.65, {"MOSS_SOUND_VOLUME": "loud"}) == 0.65,+ "MOSS_SOUND_VOLUME: 0.3 -> 0.3, unset -> default, 2 -> 1.0, text -> default")+check(sounds_enabled({}) is True and sounds_enabled({"MOSS_SOUNDS": "0"}) is False and sounds_enabled({"MOSS_SOUNDS": "off"}) is False,+ "MOSS_SOUNDS: unset on, 0 / off -> off")++print("C. the module: handlers hand the families to the player")+from dimos.msgs.std_msgs.String import String # noqa: E402+from dimos_lcm.std_msgs import Bool # noqa: E402++mod = MossSounds()+asyncio.run(mod.handle_bump(Bool(data=True))) # no player yet: nothing happens, nothing raises+mod._player = MossSoundPlayer(root=ASSETS, config={"global_gap_s": 0.0}, dry_run=True) # no gap here: the bench wants every cue, the floor wants the gap+# events seconds apart on the floor: a short pause between them here, because the player drops a+# cue that arrives while its worker holds the lock (by design: never block the caller)+for call in (lambda: mod.handle_bump(Bool(data=True)),+ lambda: mod.handle_explore_cmd(Bool(data=True)),+ lambda: mod.handle_explore_done(Bool(data=True)),+ lambda: mod.handle_base_telemetry(String(data="not json")),+ lambda: mod.handle_base_telemetry(String(data=json.dumps({"stall_count": 1, "ticks": [0, 0], "bus_mV": 11800}))),+ lambda: mod.handle_base_telemetry(String(data=json.dumps({"stall_count": 1, "ticks": [RECOVERY_MIN_TICKS, 0], "bus_mV": 11800})))):+ asyncio.run(call())+ time.sleep(0.15)+mod._player.wait_idle(timeout=8)+played = [s.get("event") for s in mod._player.drain_status() if s.get("event")]+check({"bump_surprise", "resume", "mission_complete", "recovery_success"} <= set(played),+ f"bump, explore_cmd, explore_done and a recovery reached the player: {sorted(set(played))}")+check(mod.set_volume(0.2) is True and abs(mod._player.volume - 0.2) < 1e-9 and mod.set_mute(True) is True and mod._player.muted,+ "set_volume / set_mute reach the player")+mod._player.close()+check(MossSounds().set_mute(True) is False, "set_mute without a player answers False, never raises")+check(set(MossSounds.__annotations__) == {"bump", "base_telemetry", "explore_cmd", "explore_done"},+ f"Ins only: bump, base_telemetry, explore_cmd, explore_done ({sorted(MossSounds.__annotations__)})")++print("D. hygiene: the vendored player and the pack carry no workshop context")+import re # noqa: E402+texts = [(ROOT / "moss_dimos" / "sound_pack" / "player.py").read_text(), (ASSETS / "manifest.json").read_text(), (ASSETS / "config.json").read_text()]+check(not any(re.search(r"\b(20\d\d-\d\d-\d\d|\d\d/\d\d/20\d\d)\b", t) for t in texts), "no date in the player, the manifest or the config")+check(all(ord(ch) < 128 for t in texts for ch in t), "ASCII only (English)")++print(f"\n{OK} OK, {KO} KO")+print("TEST PASSED" if KO == 0 else "TEST FAILED")+sys.exit(1 if KO else 0)diff --git a/docs/cockpit.md b/docs/cockpit.mdindex 2d6e54d..3e07a49 100644--- a/docs/cockpit.md+++ b/docs/cockpit.md@@ -80,6 +80,15 @@ firmware 300 ms after the last drive.table top the rover has turned away from keeps its wall until the camera looksat that spot again and sees nothing. The knobs are `MOSS_HIT_CAP`,`MOSS_FREE_FLOOR` and `MOSS_RAY_MAX_M` (below);+- the sound module (`moss_dimos/sounds.py`): a pack of short synthesized cues in+ `assets/sounds` played through the robot user's PulseAudio session (a Bluetooth+ speaker once connected, the default sink otherwise) on confirmed events only: the+ stack up, a contact, the tracks moving again after a stall, the order to explore,+ the end of an exploration, the battery crossing low and critical (with hysteresis).+ Each cue has a cooldown and the player keeps a gap between cues, so the rover+ never chatters. `MOSS_SOUNDS=0` leaves it out, `MOSS_SOUND_VOLUME` (0 to 1) and+ `MOSS_SOUND_SINK` (a PulseAudio sink name) tune it; a stack launched as a system+ service has no audio session and stays silent;- the RealSense colour stream at 640x480, 5 fps, carried as JPEG on the bus, and itsdepth aligned to colour at the same rate, which `lidar_odometry` turns into obstaclepoints from 12 cm (the camera's close-range depth) to 3 m, drawn in amber on the mapdiff --git a/moss_dimos/blueprints.py b/moss_dimos/blueprints.pyindex 62a25b1..5851cf0 100644--- a/moss_dimos/blueprints.py+++ b/moss_dimos/blueprints.py@@ -34,6 +34,10 @@ Switches (env, read when moss-nav / moss-explore is built; robot_profile.env_onparses them: 0, false, no or off = off, any other value = on, unset = the default):MOSS_CAMERA=0 no RealSense (default on: colour 640x480 @ 5 fps, JPEG on the bus, plus depth alignedto colour at the same rate, turned into map obstacles by lidar_odometry)+ MOSS_SOUNDS=0 no sound module (default on when pw-play or paplay is on the PATH: the sound pack+ in assets/sounds plays boot_ready, bump_surprise, recovery_success, resume,+ mission_complete, battery_low / battery_critical on the stack's events;+ MOSS_SOUND_VOLUME 0..1, MOSS_SOUND_SINK = a PulseAudio sink; see moss_dimos/sounds.py)MOSS_WRIST=0 no wrist camera (default on: the UVC camera on the arm, 640x480 @ 5 fps,JPEG on the bus as wrist_image; absent device = warning, module skipped)MOSS_WRIST_DEV wrist camera: a /dev/videoN path or an index, instead of the by-id lookup@@ -447,6 +451,14 @@ def _common_parts(ports: dict, profile: RobotProfile) -> list:if serial:cam_kwargs["serial_number"] = serialparts.append(RealSenseCamera.blueprint(**cam_kwargs))+ if robot_profile.env_on("MOSS_SOUNDS", True):+ from moss_dimos.sounds import MossSounds, playback_backend+ if playback_backend() is None:+ _logger.warning("MOSS blueprint: no sound playback command on the PATH (pw-play / paplay): "+ "the sound module is left out, the rover stays silent")+ else:+ sink = os.environ.get("MOSS_SOUND_SINK", "").strip() or None+ parts.append(MossSounds.blueprint(sink=sink))if robot_profile.env_on("MOSS_WRIST", True):idx = wrist_camera_index()if idx is None:diff --git a/moss_dimos/sound_pack/__init__.py b/moss_dimos/sound_pack/__init__.pynew file mode 100644index 0000000..e69de29diff --git a/moss_dimos/sound_pack/player.py b/moss_dimos/sound_pack/player.pynew file mode 100644index 0000000..997ee5a--- /dev/null+++ b/moss_dimos/sound_pack/player.py@@ -0,0 +1,251 @@+"""Non-blocking MOSS event sounds. Python 3.9+; standard library only.++emit() queues a cue, never drives the robot, and never waits for playback.+Backend completion means the playback process exited, not proof of audibility.+"""+import argparse+from collections import OrderedDict+import json+import math+from pathlib import Path+import queue+import random+import shutil+import subprocess+import tempfile+import threading+import time++ROOT=Path(__file__).resolve().parent++def playback_command(path, backend='auto', target=None, volume=.65):+ if not math.isfinite(volume) or not 0 <= volume <= 1:+ raise ValueError('Volume must be between 0 and 1')+ if backend=='auto':+ backend=next((x for x in ('pw-play','paplay','afplay') if shutil.which(x)),None)+ if backend not in ('pw-play','paplay','afplay') or not shutil.which(backend):+ raise RuntimeError('No supported playback backend; select pw-play, paplay, or afplay')+ if backend=='pw-play':+ cmd=[backend,f'--volume={volume:.3f}']+ if target:cmd.append(f'--target={target}')+ elif backend=='paplay':+ cmd=[backend,f'--volume={round(volume*65536)}','--client-name=MOSS','--stream-name=MOSS reaction']+ if target:cmd.append(f'--device={target}')+ else:+ if target:raise ValueError('afplay uses the macOS selected output; omit target')+ cmd=[backend,'-v',str(volume)]+ return cmd+[str(path)]++class MossSoundPlayer:+ def __init__(self, root=ROOT, config=None, dry_run=False):+ self.root=Path(root).resolve()+ self.manifest=json.loads((self.root/'manifest.json').read_text())+ self.config=json.loads((self.root/'config.json').read_text())+ if config:self.config.update(config)+ self.volume=float(self.config['volume'])+ if not math.isfinite(self.volume) or not 0<=self.volume<=1:raise ValueError('Invalid volume')+ self.rules={}+ for name,rule in self.manifest['events'].items():+ rule=dict(rule);rule.update(self.config.get('events',{}).get(name,{}))+ self.rules[name]=rule+ self.dry_run=dry_run;self.muted=bool(self.config['mute']);self.closed=False+ self.lock=threading.Condition();self.pending=[];self.current=None+ self.last_started={};self.last_variant={};self.last_end=-float('inf')+ self.ids=OrderedDict();self.status=queue.Queue(maxsize=128)+ self.rng=random.Random();self.worker=threading.Thread(target=self._run,name='moss-audio',daemon=True)+ self.worker.start()++ def _status(self, state, **details):+ row={'state':state,**details}+ try:self.status.put_nowait(row)+ except queue.Full:+ try:self.status.get_nowait()+ except queue.Empty:pass+ self.status.put_nowait(row)++ def drain_status(self):+ result=[]+ while True:+ try:result.append(self.status.get_nowait())+ except queue.Empty:return result++ def emit(self, event, event_id=None):+ """Return True if queued. False means suppressed; no playback promise.++ A busy audio worker causes this call to drop the cue rather than block.+ Call on confirmed state transitions, never on every telemetry frame.+ """+ if event not in self.rules:return False+ if event_id is not None and (not isinstance(event_id,str) or len(event_id)>200):return False+ if not self.lock.acquire(blocking=False):return False+ try:+ now=time.monotonic();rule=self.rules[event]+ if self.closed or self.muted or self.volume==0:return False+ if not rule['enabled'] and not self.config['personality']:return False+ if now-self.last_started.get(event,-float('inf'))<rule['cooldown_s']:return False+ self.pending=[p for p in self.pending if p['expires']>now]+ if any(p['event']==event for p in self.pending):return False+ while self.ids and next(iter(self.ids.values()))<=now:self.ids.popitem(last=False)+ key=(event,event_id) if event_id is not None else None+ if key is not None and key in self.ids:return False+ if len(self.pending)>=int(self.config['queue_limit']):+ low=min(self.pending,key=lambda p:p['priority'])+ if rule['priority']<=low['priority']:return False+ self.pending.remove(low)+ self.pending.append({'event':event,'priority':rule['priority'],'created':now,'expires':now+rule['ttl_s']})+ if key is not None:+ self.ids[key]=now+self.config['event_id_window_s']+ while len(self.ids)>int(self.config['dedup_limit']):self.ids.popitem(last=False)+ self.lock.notify();return True+ finally:self.lock.release()++ def set_mute(self, muted=True):+ with self.lock:+ self.muted=bool(muted)+ if self.muted:self.pending.clear()+ self.lock.notify()++ def set_volume(self, volume):+ if not math.isfinite(volume) or not 0<=volume<=1:raise ValueError('Invalid volume')+ with self.lock:self.volume=volume;self.lock.notify()++ def _finish(self, state, terminate=False):+ current=self.current+ if current is None:return+ p=current['process']+ if terminate and p.poll() is None:+ p.terminate()+ try:p.wait(timeout=.25)+ except subprocess.TimeoutExpired:p.kill();p.wait(timeout=.5)+ error=''+ if state in ('failed','timeout'):+ current['stderr'].seek(0);error=current['stderr'].read(2048).decode('utf-8','replace')+ current['stderr'].close()+ self._status(state,event=current['event'],sound=current['sound'],returncode=p.poll(),error=error)+ self.current=None;self.last_end=time.monotonic()++ def _run(self):+ try:+ while True:+ with self.lock:+ now=time.monotonic()+ if self.closed:+ self.pending.clear();self._finish('stopped',True);return+ if self.muted or self.volume==0:+ self.pending.clear();self._finish('muted',True);self.lock.wait(.025);continue+ if self.current:+ code=self.current['process'].poll()+ if code is not None:self._finish('finished' if code==0 else 'failed')+ elif now>=self.current['deadline']:self._finish('timeout',True)+ fresh=[]+ for item in self.pending:+ if item['expires']>now:fresh.append(item)+ else:self._status('expired',event=item['event'])+ self.pending=fresh+ item=min(self.pending,key=lambda p:(-p['priority'],p['created'])) if self.pending else None+ # Critical battery feedback can interrupt a lower-priority cue.+ if self.current and item and item['priority']>=90 and item['priority']>self.current['priority']:+ self._finish('preempted',True)+ if self.current or item is None:+ self.lock.wait(.025);continue+ if item['priority']<75 and now-self.last_end<self.config['global_gap_s']:+ self.lock.wait(.025);continue+ self.pending.remove(item);name=item['event'];rule=self.rules[name]+ if now-self.last_started.get(name,-float('inf'))<rule['cooldown_s']:continue+ options=[v for v in rule['variants'] if v!=self.last_variant.get(name)] or rule['variants']+ sound=self.rng.choice(options);asset=self.manifest['assets'][sound]+ path=(self.root/asset['path']).resolve()+ if self.root not in path.parents or not path.is_file():+ self._status('failed',event=name,error='Invalid or missing asset');continue+ if self.dry_run:+ self._status('simulated',event=name,sound=sound)+ self.last_variant[name]=sound;self.last_started[name]=now;self.last_end=now;continue+ err=None+ try:+ cmd=playback_command(path,self.config['backend'],self.config.get('target'),self.volume)+ err=tempfile.TemporaryFile()+ proc=subprocess.Popen(cmd,stdin=subprocess.DEVNULL,stdout=subprocess.DEVNULL,stderr=err)+ except (OSError,ValueError,RuntimeError) as exc:+ if err:err.close()+ self._status('failed',event=name,error=str(exc));continue+ self.current={**item,'sound':sound,'process':proc,'stderr':err,'deadline':time.monotonic()+asset['duration_s']+4}+ self.last_variant[name]=sound;self.last_started[name]=now+ self._status('started',event=name,sound=sound)+ except Exception as exc:+ # Audio failures stay within this optional subsystem.+ with self.lock:+ self.closed=True;self.pending.clear()+ try:self._finish('failed',True)+ finally:self._status('worker_failed',error=str(exc))++ def wait_idle(self, timeout=8):+ """Convenience for CLI/tests only; do not call from motion control."""+ end=time.monotonic()+timeout+ while time.monotonic()<end:+ with self.lock:+ if not self.pending and self.current is None:return True+ time.sleep(.02)+ return False++ def close(self):+ with self.lock:self.closed=True;self.lock.notify()+ self.worker.join(timeout=2)++ def __enter__(self):return self+ def __exit__(self,*args):self.close()++def main():+ parser=argparse.ArgumentParser(description=__doc__)+ parser.add_argument('--backend',choices=['auto','pw-play','paplay','afplay'])+ parser.add_argument('--target',help='Exact PipeWire node name or PulseAudio sink name')+ parser.add_argument('--volume',type=float)+ parser.add_argument('--dry-run',action='store_true')+ parser.add_argument('--personality',action='store_true',help='Enable optional decorative events')+ sub=parser.add_subparsers(dest='command',required=True)+ sub.add_parser('list');p=sub.add_parser('play');p.add_argument('event')+ p=sub.add_parser('audition');p.add_argument('sound')+ sub.add_parser('demo');sub.add_parser('listen')+ args=parser.parse_args();manifest=json.loads((ROOT/'manifest.json').read_text())+ if args.command=='list':+ for name,rule in manifest['events'].items():print(f"{name:24} {'on' if rule['enabled'] else 'optional':8} {rule['description']}")+ return 0+ config=json.loads((ROOT/'config.json').read_text())+ for key in ('backend','target','volume'):+ if getattr(args,key) is not None:config[key]=getattr(args,key)+ if args.personality:config['personality']=True+ if args.command in ('demo','audition'):+ if args.command=='demo':path=ROOT/'preview/MOSS_Character_Demo.wav';timeout=40+ else:+ if args.sound not in manifest['assets']:parser.error('Unknown sound ID')+ asset=manifest['assets'][args.sound];path=ROOT/asset['path'];timeout=asset['duration_s']+4+ cmd=playback_command(path,config['backend'],config.get('target'),config['volume'])+ if args.dry_run:print(json.dumps({'state':'dry_run_command','command':cmd}));return 0+ try:return subprocess.run(cmd,timeout=timeout,check=False).returncode+ except subprocess.TimeoutExpired:print('Audio backend timed out');return 1+ if args.command=='play':+ if args.event not in manifest['events']:parser.error('Unknown event')+ config['events']={**config.get('events',{}),args.event:{'enabled':True}}+ failed=False+ with MossSoundPlayer(ROOT,config,args.dry_run) as player:+ if args.command=='play':+ accepted=player.emit(args.event);print(json.dumps({'accepted':accepted,'event':args.event}),flush=True)+ failed=not accepted+ else:+ import sys+ for line in sys.stdin:+ try:+ obj=json.loads(line)+ if not isinstance(obj,dict):raise ValueError('Expected a JSON object')+ if obj.get('command')=='mute':player.set_mute(bool(obj.get('value',True)));continue+ if obj.get('command')=='volume':player.set_volume(float(obj['value']));continue+ event=obj['event'];accepted=player.emit(event,obj.get('id'))+ print(json.dumps({'accepted':accepted,'event':event}),flush=True)+ except (ValueError,KeyError,TypeError) as exc:print(json.dumps({'input_error':str(exc)}),flush=True)+ for row in player.drain_status():print(json.dumps(row),flush=True)+ if not player.wait_idle(8):failed=True+ for row in player.drain_status():+ print(json.dumps(row),flush=True)+ if row['state'] in ('failed','worker_failed','timeout'):failed=True+ return 1 if failed else 0++if __name__=='__main__':raise SystemExit(main())diff --git a/moss_dimos/sounds.py b/moss_dimos/sounds.pynew file mode 100644index 0000000..444ab16--- /dev/null+++ b/moss_dimos/sounds.py@@ -0,0 +1,247 @@+"""MossSounds: the rover's nonverbal voice, a sound pack played on confirmed events.++Sixty short synthesized cues (assets/sounds, twenty event families, three+variants each) and a non-blocking player (sound_pack/player.py: one subprocess+per cue through PulseAudio's `paplay` or PipeWire's `pw-play`, cooldown per+event, priority queue, a global gap so the rover never chatters). This module+maps the stack's events onto the families that EXIST on the robot today;+every other family stays silent until its event does.++ In bump : Bool a contact (the base's stall guard, the explorer's back-off) -> bump_surprise+ In base_telemetry : String JSON from the coordinator (2 Hz): stall_count, bus_mV ->+ recovery_success once the tracks move again after a stall,+ battery_low / battery_critical on the bus voltage (hysteresis)+ In explore_cmd : Bool the order to explore -> resume+ In explore_done : Bool the explorer found nothing left -> mission_complete++boot_ready plays once when the module starts (the stack is up). Nothing plays+twice in a row within an event's cooldown, and nothing plays while muted.++Environment: MOSS_SOUNDS (on by default; 0 = the blueprint leaves the module+out), MOSS_SOUND_VOLUME (0..1, default from assets/sounds/config.json),+MOSS_SOUND_SINK (a PulseAudio sink name or index; default = the session's+default sink, which is the Bluetooth speaker once it is connected).++The player needs the user's audio session: a stack launched from a login+shell or over ssh as the robot's user finds it (XDG_RUNTIME_DIR); a system+service would not. Without a backend the module logs once and stays silent.+"""+from __future__ import annotations++import json+import os+import shutil+import time+from pathlib import Path+from typing import Any++from dimos.core.core import rpc+from dimos.core.module import Module+from dimos.core.stream import In+from dimos.msgs.std_msgs.String import String+from dimos.utils.logging_config import setup_logger+from dimos_lcm.std_msgs import Bool++from moss_dimos import robot_profile++logger = setup_logger()++ASSETS_DIR = Path(__file__).resolve().parent.parent / "assets" / "sounds"+BACKENDS = ("pw-play", "paplay")+BATTERY_LOW_MV = 11000 # 3S pack: low below this at rest...+BATTERY_LOW_CLEAR_MV = 11300 # ...and back to normal above this (hysteresis: a sag under load does not toggle it)+BATTERY_CRITICAL_MV = 10600 # the flight check refuses below 10.8 V; critical is lower still+BATTERY_SAMPLES = 6 # consecutive telemetry lines (3 s at 2 Hz) below a threshold before it counts+RECOVERY_WINDOW_S = 20.0 # a stall followed by motion inside this window = a recovery+RECOVERY_MIN_TICKS = 100 # encoder ticks that count as "moving again" after a stall+++def sound_volume(default: float, env: dict | None = None) -> float:+ """MOSS_SOUND_VOLUME clamped to 0..1; unset or unreadable -> default."""+ raw = (env if env is not None else os.environ).get("MOSS_SOUND_VOLUME", "")+ try:+ v = float(raw)+ except (TypeError, ValueError):+ return default+ if v != v:+ return default+ return max(0.0, min(1.0, v))+++def playback_backend() -> str | None:+ """The first playback command on the PATH, None when there is none."""+ for name in BACKENDS:+ if shutil.which(name):+ return name+ return None+++class EventMapper:+ """The stack's events -> sound families, with the state the decisions need.+ Pure: call `on_*` and read the list of family names it returns; the module+ hands them to the player. Benched without audio."""++ def __init__(self, now: float | None = None) -> None:+ self._stalls = 0+ self._stall_t: float | None = None+ self._stall_ticks: tuple[int, int] | None = None+ self._battery_state = "ok" # ok | low | critical+ self._below_low = 0+ self._below_critical = 0++ def on_bump(self, data: bool) -> list[str]:+ return ["bump_surprise"] if data else []++ def on_explore_cmd(self, data: bool) -> list[str]:+ return ["resume"] if data else []++ def on_explore_done(self, data: bool) -> list[str]:+ return ["mission_complete"] if data else []++ def on_telemetry(self, doc: dict, now: float) -> list[str]:+ out: list[str] = []+ out += self._stall_events(doc, now)+ out += self._battery_events(doc)+ return out++ def _stall_events(self, doc: dict, now: float) -> list[str]:+ """A new stall remembers the ticks; motion of RECOVERY_MIN_TICKS on+ either track within RECOVERY_WINDOW_S after it = recovery_success.+ (The contact cue itself comes from `bump`, published by the coordinator.)"""+ out: list[str] = []+ stalls = int(doc.get("stall_count") or 0)+ ticks = doc.get("ticks")+ ticks = (int(ticks[0]), int(ticks[1])) if isinstance(ticks, (list, tuple)) and len(ticks) == 2 else None+ if stalls > self._stalls:+ self._stalls = stalls+ self._stall_t = now+ self._stall_ticks = ticks+ return out+ if self._stall_t is not None and ticks is not None and self._stall_ticks is not None:+ if now - self._stall_t > RECOVERY_WINDOW_S:+ self._stall_t = None+ elif max(abs(ticks[0] - self._stall_ticks[0]), abs(ticks[1] - self._stall_ticks[1])) >= RECOVERY_MIN_TICKS:+ self._stall_t = None+ out.append("recovery_success")+ return out++ def _battery_events(self, doc: dict) -> list[str]:+ """ok -> low below BATTERY_LOW_MV for BATTERY_SAMPLES lines, low -> ok above+ BATTERY_LOW_CLEAR_MV; low -> critical below BATTERY_CRITICAL_MV for the+ same count. Each entry into low or critical plays once."""+ mv = doc.get("bus_mV")+ try:+ mv = int(mv)+ except (TypeError, ValueError):+ return []+ if mv <= 0:+ return []+ out: list[str] = []+ self._below_low = self._below_low + 1 if mv < BATTERY_LOW_MV else 0+ self._below_critical = self._below_critical + 1 if mv < BATTERY_CRITICAL_MV else 0+ if self._battery_state == "ok" and self._below_low >= BATTERY_SAMPLES:+ self._battery_state = "low"+ out.append("battery_low")+ if self._battery_state == "low" and self._below_critical >= BATTERY_SAMPLES:+ self._battery_state = "critical"+ out.append("battery_critical")+ if self._battery_state != "ok" and mv > BATTERY_LOW_CLEAR_MV:+ self._battery_state = "ok"+ return out+++class MossSounds(Module):+ """The sound pack on the bus. Ins only; see the module docstring."""++ bump: In[Bool]+ base_telemetry: In[String]+ explore_cmd: In[Bool]+ explore_done: In[Bool]++ def __init__(self, assets_dir: str | None = None, volume: float | None = None,+ sink: str | None = None, **kwargs: Any) -> None:+ super().__init__(**kwargs)+ self._assets_dir = Path(assets_dir) if assets_dir else ASSETS_DIR+ self._volume = volume+ self._sink = sink+ self._player = None+ self._mapper = EventMapper()+ self._silent_reason: str | None = None++ @rpc+ def start(self) -> None:+ super().start()+ backend = playback_backend()+ if backend is None:+ self._silent_reason = f"no playback backend on the PATH ({' / '.join(BACKENDS)})"+ logger.warning(f"MOSS sounds: {self._silent_reason} - the rover stays silent")+ return+ try:+ from moss_dimos.sound_pack.player import MossSoundPlayer+ config = {"backend": backend}+ if self._sink:+ config["target"] = self._sink+ self._player = MossSoundPlayer(root=self._assets_dir, config=config)+ vol = sound_volume(self._player.volume) if self._volume is None else self._volume+ self._player.set_volume(vol)+ except Exception as exc: # noqa: BLE001 - a broken pack never stops the stack+ self._silent_reason = f"{type(exc).__name__}: {exc}"+ logger.warning(f"MOSS sounds: player not started ({self._silent_reason}) - the rover stays silent")+ self._player = None+ return+ logger.info(f"MOSS sounds: up, {len(self._player.rules)} event families, backend {backend}, "+ f"sink {self._sink or 'default'}, volume {self._player.volume:.2f}, assets {self._assets_dir}")+ self._play(["boot_ready"])++ @rpc+ def stop(self) -> None:+ if self._player is not None:+ try:+ self._player.close()+ except Exception: # noqa: BLE001+ pass+ self._player = None+ super().stop()++ @rpc+ def set_mute(self, muted: bool = True) -> bool:+ if self._player is None:+ return False+ self._player.set_mute(bool(muted))+ return True++ @rpc+ def set_volume(self, volume: float) -> bool:+ if self._player is None:+ return False+ self._player.set_volume(max(0.0, min(1.0, float(volume))))+ return True++ def _play(self, families: list[str]) -> None:+ if self._player is None:+ return+ for name in families:+ queued = self._player.emit(name)+ logger.info(f"MOSS sounds: {name} {'queued' if queued else 'suppressed (cooldown, mute or queue)'}")++ async def handle_bump(self, msg: Bool) -> None:+ self._play(self._mapper.on_bump(bool(getattr(msg, "data", False))))++ async def handle_explore_cmd(self, msg: Bool) -> None:+ self._play(self._mapper.on_explore_cmd(bool(getattr(msg, "data", False))))++ async def handle_explore_done(self, msg: Bool) -> None:+ self._play(self._mapper.on_explore_done(bool(getattr(msg, "data", False))))++ async def handle_base_telemetry(self, msg: String) -> None:+ try:+ doc = json.loads(getattr(msg, "data", "") or "{}")+ except (TypeError, ValueError):+ return+ if isinstance(doc, dict):+ self._play(self._mapper.on_telemetry(doc, time.monotonic()))+++def sounds_enabled(env: dict | None = None) -> bool:+ """MOSS_SOUNDS: on unless set to 0 / false / no / off."""+ return robot_profile.env_on("MOSS_SOUNDS", True, env)