# Tauri Plugin TTS (Text-to-Speech)
Native Text-to-Speech plugin for Tauri 2.x applications. Provides cross-platform TTS functionality for desktop (Windows, macOS, Linux) and mobile (iOS, Android).
## Features
- ๐ฃ๏ธ **Speak text** with customizable rate, pitch, and volume
- ๐ **Multi-language support** - Set language/locale for speech
- ๐๏ธ **Voice selection** - Get available voices and filter by language
- โน๏ธ **Control playback** - Stop speech and check speaking status
- ๐ฑ **Cross-platform** - Works on desktop and mobile
## Installation
### Rust
Add the plugin to your `Cargo.toml`:
```toml
[dependencies]
tauri-plugin-tts = { path = "../tauri-plugin-tts" }
```
### Register the plugin
In your `src-tauri/src/lib.rs`:
```rust
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_tts::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
```
### Permissions
Add permissions to your `capabilities/default.json`:
```json
{
"permissions": ["tts:default"]
}
```
## Usage
### TypeScript/JavaScript
```typescript
import { speak, stop, getVoices, isSpeaking } from "tauri-plugin-tts-api";
// Simple speech
await speak({ text: "Hello, world!" });
// With options
await speak({
text: "Olรก, mundo!",
language: "pt-BR",
rate: 0.8, // 0.5 to 2.0
pitch: 1.2, // 0.5 to 2.0
volume: 1.0, // 0.0 to 1.0
});
// Stop speaking
await stop();
// Get all voices
const voices = await getVoices();
// Get voices for a specific language
const englishVoices = await getVoices("en");
// Check if speaking
const speaking = await isSpeaking();
```
### Rust
```rust
use tauri_plugin_tts::TtsExt;
// In a command or setup
fn my_command(app: tauri::AppHandle) {
let tts = app.tts();
tts.speak(SpeakRequest {
text: "Hello!".into(),
language: Some("en-US".into()),
rate: 1.0,
pitch: 1.0,
volume: 1.0,
}).unwrap();
}
```
## Platform Support
| Windows | โ
Full support (SAPI) |
| macOS | โ
Full support (AVSpeechSynthesizer) |
| Linux | โ
Full support (speech-dispatcher) |
| iOS | โ
Full support (AVSpeechSynthesizer) |
| Android | โ
Full support (TextToSpeech) |
## API Reference
### `speak(options: SpeakOptions): Promise<void>`
Speak the given text.
**Options:**
- `text` (required): The text to speak
- `language`: Language/locale code (e.g., "en-US", "pt-BR")
- `voiceId`: Specific voice ID from `getVoices()` (takes priority over `language`)
- `rate`: Speech rate (0.25 = quarter, 0.5 = half, 1.0 = normal, 2.0 = double)
- `pitch`: Voice pitch (0.5 = low, 1.0 = normal, 2.0 = high)
- `volume`: Volume level (0.0 = silent, 1.0 = full)
### `stop(): Promise<void>`
Stop any ongoing speech immediately.
### `getVoices(language?: string): Promise<Voice[]>`
Get available voices, optionally filtered by language.
### `isSpeaking(): Promise<boolean>`
Check if TTS is currently speaking.
## License
MIT