Skip to main content

Crate product_os_voice

Crate product_os_voice 

Source
Expand description

Product OS : Voice — text-to-speech and voice generation with pluggable backends.

This library provides a unified API for synthesizing speech from text. Multiple backends can be enabled via feature flags: local TTS (Piper, eSpeak NG, Edge TTS) or cloud (AWS Polly).

Library-handled setup: The piper (subprocess) backend is fully handled by the library—no shell scripts. Call create_engine with "piper" and None config to trigger download and setup. This works without piper-rs. The piper_embedded backend is optional and may have dependency constraints (e.g. piper-rs, cmake for first build).

§Features

  • piper: Piper TTS (subprocess; binary and ONNX model auto-downloaded when config is None). Recommended.
  • piper_embedded: Piper TTS in-process via piper-rs (optional; dependency compatibility may vary).
  • kokoro_embedded: Kokoro TTS in-process via ONNX Runtime + eSpeak phonemization (optional).
  • sherpa_embedded: Sherpa-ONNX offline VITS via C API + same ONNX Runtime as Piper/Kokoro (optional; requires native Sherpa libs).
  • espeak: eSpeak NG (requires espeak-ng binary on PATH).
  • edge_tts: Edge TTS (requires edge-tts on PATH or python3 with pip install edge-tts; no API key).
  • aws_polly: AWS Polly (requires AWS credentials and network).

No backend is enabled by default; add the feature you need.

§Example

use product_os_voice::{create_engine, VoiceEngine, VoiceOptions};
use std::path::PathBuf;

let engine = product_os_voice::create_engine("piper", None).expect("piper feature enabled");
// Piper requires a model; in real use configure with PiperEngine::new().with_model(path)
let options = VoiceOptions::default();
let audio = engine.synthesize("Hello, world!", &options);
if let Ok(bytes) = audio {
    std::fs::write("output.wav", bytes).expect("write");
}

§Doc-test

Building options and error types (no backend required):

use product_os_voice::{AudioFormat, VoiceOptions};

let opts = VoiceOptions {
    sample_rate: Some(16000),
    format: AudioFormat::Wav,
    ..Default::default()
};
assert_eq!(opts.sample_rate, Some(16000));

Re-exports§

pub use config::EngineConfig;
pub use engine::AudioFormat;
pub use engine::VoiceEngine;
pub use engine::VoiceInfo;
pub use engine::VoiceOptions;
pub use error::VoiceError;

Modules§

backends
Voice engine backends (local and cloud).
config
Engine configuration for backends that require credentials or paths.
engine
Core types and trait for voice synthesis.
error
Error types for voice synthesis operations.
platform
Platform-specific behavior for voice backends (macOS, iOS, Android).

Functions§

create_engine
Create a voice engine by name, with optional backend-specific config.