Metadata-Version: 2.4
Name: sayback
Version: 0.1.0
Summary: Accessible, code-aware, multi-language voice reader (MCP server + CLI controller) for AI coding agents.
Author: Sayback Contributors
License: MIT
Project-URL: Homepage, https://github.com/ELLPAA/sayback
Project-URL: Repository, https://github.com/ELLPAA/sayback
Project-URL: Issues, https://github.com/ELLPAA/sayback/issues
Keywords: mcp,tts,accessibility,edge-tts,voice,claude-code,cursor,kilo-code,screen-reader
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: edge-tts>=6.1.12
Dynamic: license-file

# Sayback

[![CI](https://github.com/ELLPAA/sayback/actions/workflows/ci.yml/badge.svg)](https://github.com/ELLPAA/sayback/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
[![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/)
[![Status: Alpha](https://img.shields.io/badge/status-v0.1.0%20alpha-orange.svg)](https://github.com/ELLPAA/sayback/releases)

**Accessible, code-aware voice reader for AI coding agents — MCP Server, VS Code/Cursor Visual Player & Live Terminal Controller.**

> **[راهنمای فارسی (Persian Documentation)](README.fa.md)**

---

## Why Sayback?

Developers dealing with eye strain, low vision, or screen fatigue often struggle to read 20–200 line responses from AI coding agents (**Claude Code, Cursor, Kilo Code, Cline, Roo Code, OpenCode**).

- Basic `tts-mcp` wrappers dump the entire text into one uninterruptible `speak()` call with no pause, resume, or chunk navigation.
- Full screen readers (VoiceOver / NVDA) read every bracket, markdown symbol, and code diff aloud.
- Local neural TTS stacks typically require heavy GPUs or paid API keys.

**Sayback** is a lightweight, zero-GPU, zero-API-key companion across **macOS, Linux, and Windows** (`v0.1.0` early alpha release).

---

## Key Features

- **Chunked Playback with Persistent Resume:** Splits long explanations into natural 1–2 sentence chunks, prefetches upcoming chunks asynchronously to minimize pauses between sentences, and persists progress in `state.json`. Even hours later—after the background daemon exits to free RAM—`sayback resume` continues from the beginning of the saved chunk.
- **Code-Aware Sanitizer:** Strips fenced code blocks (including 4-backtick and unclosed fences), unified `git diff` hunks, terminal ANSI escape codes, and raw URLs while preserving inline code identifiers (including generics like `Vec<u8>`) and shortening long file paths to basenames.
- **12-Language Auto-Detection (Anchor Language):** Detects `en`, `fa`, `ar`, `tr`, `de`, `fr`, `es`, `ru`, `zh`, `ja`, `ko`, and `hi` without ML dependencies, separates Persian from Arabic, supports spaceless CJK chunking, and preserves independent language/voice metadata when multiple messages are queued (`enqueue`).
- **Non-Blocking MCP Server + Stop Hook:** Returns control to your AI agent immediately once queued (warm daemon calls complete quickly; cold-starting the daemon on the first call takes ~0.5–1.5s). Includes a fault-tolerant `sayback hook` for Claude Code Stop hooks.
- **Single-Instance Local Daemon:** Binds strictly to `127.0.0.1` with a per-session random token (`compare_digest`), serializes concurrent playback commands, prevents overlapping audio across multiple IDE windows, and auto-exits after idle timeout.
- **Visual Player (VS Code / Cursor) & Live Terminal Controller:**
  - **VS Code / Cursor Extension:** Uncluttered Status Bar on the right (expands wide `Prev`, `Pause/Resume 3/12`, `Next`, `Replay`, `Stop` controls only while active) + Bottom Panel player with dynamic 12-language voice selector, speed presets, `S/M/L/XL` scaling, ARIA/screen-reader labels, and automatic RTL/LTR (`dir="auto"`) chunk display.
  - **Terminal Live Controller (`sayback controller`):** Zero-dependency keyboard player (`Space`, `←/→`, `r`, `c`, `s`, `+/-`, `q`) for macOS, Linux, and Windows terminal workflows.

---

## Privacy & Offline Behavior

Please review how Sayback handles text and network requests before using it on sensitive repositories:

- **Online Neural TTS (`edge-tts`):** By default, Sayback sends the **sanitized prose** (after stripping code blocks and diffs) over HTTPS/WebSocket to Microsoft Edge's online neural TTS service (no API key or account required; Sayback itself collects zero telemetry).
- **Not a Secret Redactor:** The sanitizer is designed for listening comfort, **not** secret scrubbing. Do not ask Sayback to read `.env` files, API keys, or confidential credentials aloud.
- **Offline Fallback & Circuit Breaker:** If you are offline or `edge-tts` is unreachable, Sayback opens a 60-second circuit breaker and automatically falls back to your OS speech engine (`SAYBACK_TTS_ENGINE=system` forces offline-only mode permanently):
  - **macOS:** Built-in `say` (supports English and installed system voices; note that macOS does **not** ship a default built-in Persian/Arabic/CJK voice unless manually downloaded).
  - **Windows:** Built-in `System.Speech` (SAPI) via UTF-8 stdin.
  - **Linux:** `espeak-ng` or `espeak` (if installed).
- **Local Disk Storage & Cleanup:** Playback state (`state.json`) and cached audio files (`audio/`) are stored in private user directories (`0700` dirs / `0600` files on POSIX; no message history is retained). Run `sayback clear` anytime to wipe saved state and cached audio immediately.

---

## Installation

### 1. Python Core (CLI + MCP Server)

```bash
# Recommended (isolated CLI install from PyPI)
pipx install sayback

# Or with uv
uv tool install sayback

# Or inside a virtual environment
pip install sayback

# Or install the latest commit directly from GitHub
pipx install "git+https://github.com/ELLPAA/sayback.git"
```

> **Linux Audio Prerequisite:** Ensure at least one audio player is installed for MP3/WAV playback (`mpv`, `ffmpeg`/`ffplay`, or `mpg123`). For offline fallback on Linux, install `espeak-ng`.

Verify your audio engine and TTS setup:

```bash
sayback doctor --live
sayback say "Sayback is ready to read your AI coding answers."
```

### 2. VS Code / Cursor Companion Extension

Download `sayback-player-0.1.0.vsix` from [GitHub Releases](https://github.com/ELLPAA/sayback/releases) (or build locally via `python scripts/build_vsix.py`), then install:

```bash
code --install-extension sayback-player-0.1.0.vsix
# Or for Cursor:
cursor --install-extension sayback-player-0.1.0.vsix
```

Reload the window (`Cmd/Ctrl + Shift + P` → **Developer: Reload Window**). Click **Sayback** in the bottom-right Status Bar to open the visual player in the Bottom Panel alongside Terminal.

---

## Connecting AI Coding Agents

> **GUI Editor PATH Tip:** Editors launched from macOS Dock/Spotlight or Windows Start Menu may not inherit `~/.local/bin` in `PATH`. If your agent reports `sayback: command not found`, run `which sayback` (macOS/Linux) or `where sayback` (Windows) and paste the **absolute path** into your MCP config.

### 1. Claude Code (MCP Server or Automatic Stop Hook)

**Option A — MCP Server:**

```bash
claude mcp add sayback -- sayback mcp
```

**Option B — Automatic Stop Hook (`~/.claude/settings.json`):**

```json
{
  "hooks": {
    "Stop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "sayback hook"
          }
        ]
      }
    ]
  }
}
```

### 2. Cursor / Cline / Roo Code (`mcp.json`)

```json
{
  "mcpServers": {
    "sayback": {
      "command": "sayback",
      "args": ["mcp"]
    }
  }
}
```

### 3. Kilo Code / OpenCode (`kilo.jsonc` / `opencode.json`)

```json
{
  "mcp": {
    "sayback": {
      "type": "local",
      "command": ["sayback", "mcp"],
      "enabled": true
    }
  }
}
```

### Optional: Auto-Read Global Rule for MCP Clients

MCP registration exposes `speak` and `control` tools, but unlike Claude Code's Stop hook, clients such as **Cursor, Kilo Code, Cline, Roo Code, and OpenCode** only call `speak` automatically if instructed. Add this one-line rule to your agent's global/custom instructions whenever you want automatic spoken answers:

```text
After answering an explanation or analysis question, call the `sayback` MCP `speak` tool once with your plain-language explanation (or a concise `spoken_summary`) so I can listen hands-free.
```

**Exposed MCP Tools:**
- `speak(text, spoken_summary="", mode="replace"|"enqueue", voice="", rate="")` — Non-blocking chunked speech playback.
- `control(action="pause"|"resume"|"toggle"|"stop"|"next"|"prev"|"replay"|"repeat"|"status"|"clear")` — Playback control directly from voice/text prompts.

---

## Live Terminal Controller (Outside VS Code)

Working in **Claude Code**, **OpenCode**, or any terminal workflow? Run:

```bash
sayback controller
# Alias: sayback ui
```

| Key | Action |
| :--- | :--- |
| `Space` / `p` | Play / Pause (resumes from the start of the saved chunk) |
| `←` / `h` / `b` | Previous chunk |
| `→` / `l` / `n` | Next chunk |
| `r` | Replay entire last message from chunk 1 |
| `c` | Repeat current chunk |
| `s` | Stop playback |
| `+` / `-` | Increase / decrease speech speed |
| `q` / `Esc` | Quit controller (playback continues in background) |

---

## Built-In 12-Language Neural Voices

Sayback auto-detects the language by default (`voice="auto"`), or you can lock any voice via the VS Code dropdown or `sayback prefs --voice <alias|id>`:

| Code | Language | Default (Male) | Female |
| :--- | :--- | :--- | :--- |
| `en` | English | `en-US-AndrewNeural` (`andrew`) | `en-US-AriaNeural` (`aria`) |
| `fa` | Persian (Farsi) | `fa-IR-FaridNeural` (`farid`) | `fa-IR-DilaraNeural` (`dilara`) |
| `ar` | Arabic | `ar-SA-HamedNeural` (`hamed`) | `ar-EG-SalmaNeural` (`salma`) |
| `tr` | Turkish | `tr-TR-AhmetNeural` (`ahmet`) | `tr-TR-EmelNeural` (`emel`) |
| `de` | German | `de-DE-ConradNeural` (`conrad`) | `de-DE-KatjaNeural` (`katja`) |
| `fr` | French | `fr-FR-HenriNeural` (`henri`) | `fr-FR-DeniseNeural` (`denise`) |
| `es` | Spanish | `es-ES-AlvaroNeural` (`alvaro`) | `es-ES-ElviraNeural` (`elvira`) |
| `ru` | Russian | `ru-RU-DmitryNeural` (`dmitry`) | `ru-RU-SvetlanaNeural` (`svetlana`) |
| `zh` | Chinese | `zh-CN-YunxiNeural` (`yunxi`) | `zh-CN-XiaoxiaoNeural` (`xiaoxiao`) |
| `ja` | Japanese | `ja-JP-KeitaNeural` (`keita`) | `ja-JP-NanamiNeural` (`nanami`) |
| `ko` | Korean | `ko-KR-InJoonNeural` (`injoon`) | `ko-KR-SunHiNeural` (`sunhi`) |
| `hi` | Hindi | `hi-IN-MadhurNeural` (`madhur`) | `hi-IN-SwaraNeural` (`swara`) |

---

## CLI Quick Reference

```bash
sayback say "Hello world"        # Speak text (or pipe via stdin; use -- before text starting with -)
sayback toggle                   # Pause / resume from saved chunk
sayback prev | next              # Jump backward / forward one chunk
sayback replay | repeat          # Replay message from chunk 1 / repeat current chunk
sayback stop                     # Stop playback
sayback status                   # Show playback state and chunk progress
sayback clear                    # Wipe saved state.json and cached audio files
sayback prefs --rate +10%        # Save default speed
sayback prefs --voice auto       # Reset voice to 12-language auto-detect
sayback controller               # Open live keyboard controller
sayback doctor --live            # Run diagnostics + live synthesis check
```

---

## Platform Support Status (v0.1.0 Alpha)

| Platform | Audio Playback | Offline Fallback | Verification Status |
| :--- | :--- | :--- | :--- |
| **macOS** | Built-in `afplay` | Built-in `say` (Latin/installed voices) | Live-verified on macOS + CI |
| **Linux** | `mpv` / `ffplay` / `mpg123` / `cvlc` (MP3) + `paplay`/`aplay` (WAV) | `espeak-ng` / `espeak` | Automated CI matrix (Python 3.10–3.13); live desktop feedback welcome |
| **Windows** | Built-in `winmm` MCI (`mpegvideo`/`waveaudio`) | Built-in `System.Speech` | Automated CI matrix (Python 3.10–3.13); live desktop feedback welcome |

---

## License

MIT License — see [LICENSE](LICENSE).
