Skip to main content

Crate espeak_ng

Crate espeak_ng 

Source
Expand description

§espeak-ng-rs

A pure-Rust port of eSpeak NG text-to-speech.

The crate can be used as a drop-in replacement for the C library (libespeak-ng) from Rust code. The mapping is:

C functionRust equivalent
espeak_ng_Initialize()EspeakNg::new()
espeak_ng_SetVoiceByName()EspeakNg::set_voice()
espeak_ng_SetParameter()EspeakNg::set_parameter()
espeak_ng_Synthesize()EspeakNg::synth()
espeak_TextToPhonemes()EspeakNg::text_to_phonemes()
espeak_ng_GetSampleRate()EspeakNg::sample_rate()
espeak_ng_Terminate()drop(engine)

§Quick start

use espeak_ng::EspeakNg;

// Initialise (equivalent to espeak_ng_Initialize + espeak_ng_SetVoiceByName)
let engine = EspeakNg::new("en")?;

// Text → IPA phonemes
let ipa = engine.text_to_phonemes("hello world")?;
assert_eq!(ipa, "hɛlˈəʊ wˈɜːld");

// Text → 22 050 Hz PCM
let (samples, rate) = engine.synth("hello world")?;
assert_eq!(rate, 22050);

§Convenience functions

For one-shot calls that don’t need a persistent engine:

// Text → IPA string
let ipa = espeak_ng::text_to_ipa("en", "hello world")?;

// Text → PCM samples + sample rate
let (samples, rate) = espeak_ng::text_to_pcm("en", "hello")?;

§Module overview

ModulePurpose
(crate root)EspeakNg engine, convenience functions
encodingUTF-8 / ISO-8859-* / KOI8-R / ISCII decode
phonemeBinary phoneme table loader and IPA scanner
dictionaryDictionary lookup and rule-based translation
translateFull text → phoneme code → IPA pipeline
synthesizeHarmonic formant synthesizer → PCM
[oracle]C library FFI (feature = c-oracle)

Re-exports§

pub use translate::ipa_table;
pub use error::Error;
pub use error::Result;
pub use encoding::Encoding;
pub use encoding::TextDecoder;
pub use encoding::DecodeMode;
pub use phoneme::PhonemeData;
pub use phoneme::PhonemeTab;
pub use phoneme::PhonemeFeature;
pub use translate::Translator;
pub use translate::PhonemeCode;
pub use synthesize::Synthesizer;
pub use synthesize::VoiceParams;
pub use synthesize::PcmBuffer;
pub use engine::EspeakNg;
pub use engine::Builder;
pub use engine::Parameter;
pub use engine::VoiceSpec;
pub use engine::VoiceSpecBuilder;
pub use engine::Gender;
pub use engine::SynthEvent;
pub use engine::EventKind;
pub use engine::OutputMode;

Modules§

dictionary
Dictionary lookup, rule-based translation, and stress assignment.
encoding
Text encoding detection and decoding.
engine
Top-level drop-in replacement for the eSpeak NG C library.
error
Error types for the espeak-ng-rs library.
phoneme
Phoneme type definitions, flag constants, and binary data loader.
synthesize
Phoneme-list → audio PCM synthesis.
translate
Text → phoneme code → IPA string translation pipeline.

Constants§

BUNDLED_LANGUAGES

Functions§

bundled_languages
has_bundled_language
install_bundled_language
install_bundled_languages
text_to_ipa
Convert text to an IPA phoneme string.
text_to_pcm
Synthesize text to raw 16-bit PCM audio at 22 050 Hz (mono).