# @aaxyat/audiobook-bridge

Optional native processing bridge for **AudiobookStudio** (FFmpeg, FFprobe, multiresolution waveform generation, native silence detection, transition analysis, and M4B chapter export).

## Quick Start

Run directly via `npx` with zero prior installation:

```bash
npx @aaxyat/audiobook-bridge
```

Or with custom port and token options:

```bash
npx @aaxyat/audiobook-bridge --port 8765 --token my-secure-token
```

## Features

- **Zero Install**: Runs immediately via `npx` with Node.js >= 18.
- **FFmpeg & FFprobe Integration**: Auto-detects local system FFmpeg / FFprobe installations and hardware acceleration codecs (CUDA, QSV, VAAPI, VideoToolbox).
- **Secure by Default**:
  - Binds to `127.0.0.1` (localhost only).
  - Short-lived token authentication.
  - Strict operation whitelist (`probe`, `waveform`, `silence`, `transitionDetection`, `analyze`, `transcribe`, `export`, `cancel`, `status`).
  - No arbitrary command execution.
- **Cancellable Job System**: Real-time progress updates, elapsed time, ETA tracking, and graceful child process cleanup.
- **High-Performance Audio Processing**:
  - Fast native audio metadata probing via FFprobe.
  - Multiresolution peak/RMS waveform extraction.
  - Native silence interval detection using FFmpeg `silencedetect`.
  - M4B export with chapter markers, metadata tags, and cover art.

## Protocol

Uses a versioned localhost WebSocket protocol.

### Handshake

```json
// Client -> Bridge
{
  "type": "handshake",
  "protocolVersion": 1,
  "clientVersion": "1.0.0",
  "token": "optional-auth-token"
}

// Bridge -> Client
{
  "type": "handshake_response",
  "protocolVersion": 1,
  "bridgeVersion": "0.1.0",
  "capabilities": {
    "ffmpeg": true,
    "ffprobe": true,
    "waveform": true,
    "silence": true,
    "transitionDetection": true,
    "speechRecognition": false,
    "m4bExport": true,
    "hardwareAcceleration": true
  }
}
```

## License

MIT © 2026 aaxyat
