anyvoice-cli 0.2.0

CLI for anyvoice Text-to-Speech (Edge TTS, OpenAI, ElevenLabs)
# anyvoice-rs

Fast, unified async Text-to-Speech in Rust with native bindings for **Node.js / Bun / TypeScript** (`napi-rs`), **Python** (`PyO3`), and a **CLI** (`anyvoice`).

## Features

- **Multiple providers behind one typed interface:**
  - **Microsoft Edge Neural TTS** (`edge`) — free, zero API key, native WebSocket + `Sec-MS-GEC` clock-skew handling + `WordBoundary` timings + in-process `symphonia` MP3→PCM decoding.
  - **OpenAI & OpenAI-compatible** (`openai`) — `gpt-4o-mini-tts` (with delivery `instructions`), `tts-1`, `tts-1-hd`, streaming raw PCM, and custom `base_url` for local servers (Kokoro-FastAPI, Speaches, OpenedAI Speech).
  - **ElevenLabs** (`elevenlabs`) — streaming 24 kHz PCM + live voice listing.
- **Explicit audio formats & timings:** every `Audio` / `AudioChunk` carries `{ sample_rate, channels }`, `.duration()`, `.to_wav_bytes()`, `.convert_format()`, and `WordTiming` + WebVTT (`.to_vtt()`) export.
- **Pipelined `SpeechStream`:** prefetches upcoming sentences concurrently while playing strictly in order, with a smart `SentenceSplitter` that preserves decimals (`3.14`), versions (`v0.5.1`), URLs, and abbreviations (`Dr.`, `e.g.`).
- **Content-addressed disk cache (`CachedProvider`):** SHA-256 `.wav` + `.timings.json` cache for 0 ms / \$0 repeated runs (ideal for scripted demo videos and tests).
- **Optional native playback (`playback` feature):** cross-platform speaker output via `cpal` (no PortAudio required).

## Workspace

| Crate | Purpose |
| --- | --- |
| `crates/anyvoice` | Pure Rust core library |
| `crates/anyvoice-cli` | `anyvoice` CLI (`synthesize`, `voices`, optional `speak`) |
| `crates/anyvoice-node` | `@phil65/anyvoice` native Node.js / Bun bindings (`napi-rs`) |
| `crates/anyvoice-py` | `anyvoice-rs` async Python bindings (`PyO3` + `maturin`) |

## Quick Start

### CLI

```bash
# Free Edge TTS -> WAV + WebVTT subtitles + JSON metadata
cargo run -p anyvoice-cli -- synthesize "FormCAD builds exact B-Rep solids in WebAssembly." \
  -o hello.wav --vtt hello.vtt --json

# List English voices
cargo run -p anyvoice-cli -- voices --locale en-US

# OpenAI gpt-4o-mini-tts with style instructions + disk cache
OPENAI_API_KEY=... cargo run -p anyvoice-cli -- synthesize "Welcome to the demo." \
  -p openai -v coral --instructions "Calm, crisp product demo narrator" \
  --cache-dir .cache/voice -o demo.wav
```

### Rust

```rust
use std::sync::Arc;
use anyvoice::{CachedProvider, EdgeProvider, SynthesisRequest, TtsProvider};

#[tokio::main]
async fn main() -> anyvoice::Result<()> {
    let provider = CachedProvider::new(EdgeProvider::new(), ".cache/voice");
    let audio = provider
        .synthesize(&SynthesisRequest::new("Hello from anyvoice-rs!").speed(1.1))
        .await?;
    audio.write_wav("out.wav")?;
    println!("{} ms, {} word timings", audio.duration_ms(), audio.timings.len());
    Ok(())
}
```

### TypeScript / Node.js (`@phil65/anyvoice`)

```ts
import { VoiceClient } from "@phil65/anyvoice";

const tts = VoiceClient.edge("en-US-EmmaMultilingualNeural").withCache(".cache/voice");
const audio = await tts.synthesize("FormCAD builds exact B-Rep solids in WebAssembly.");
console.log(audio.durationMs, audio.timings.length);
```

### Python (`anyvoice_rs`)

```python
import asyncio
from anyvoice_rs import VoiceClient

async def main():
    tts = VoiceClient.edge().with_cache(".cache/voice")
    audio = await tts.synthesize("Hello from Rust-backed Python!")
    audio.write_wav("out.wav")
    print(audio.duration_ms, len(audio.timings))

asyncio.run(main())
```

## License

MIT