6 releases

0.1.5 Feb 9, 2024
0.1.4 Jan 26, 2024
0.1.2 Nov 22, 2023
0.1.1 Aug 3, 2022
0.1.0 Jul 19, 2022

#236 in Audio

Download history 14/week @ 2024-01-02 4/week @ 2024-01-16 16/week @ 2024-01-23 1/week @ 2024-02-06 9/week @ 2024-02-13 53/week @ 2024-02-20 36/week @ 2024-02-27 3/week @ 2024-03-05 5/week @ 2024-03-12 7/week @ 2024-03-19 8/week @ 2024-03-26 36/week @ 2024-04-02

52 downloads per month

MIT license

19KB
429 lines

eSpeak NG playback library

Crates.io Version Crates.io Downloads docs.rs Build Status

This library provides a rodio::Source that can be used to generate eSpeak audio. It supports listing and setting voices, triggering a callback for boundary or marker events, and full control of other eSpeak parameters like rate and pitch. See example and tests for usage.

Documentation

The documentation contains some usage examples, along with the tests and code examples in this repository.

License

Licensed under (MIT license).


lib.rs:

eSpeak NG playback library

The main use of this library is to create and configure a Speaker which in turn creates a SpeakerSource that implements a rodio::Source.

For example, here is how you would synthesize a simple phrase:

use rodio::{OutputStream, Sink};

let speaker = espeaker::Speaker::new();
let source = speaker.speak("Hello, world!");
let (_stream, stream_handle) = OutputStream::try_default().unwrap();
let sink = Sink::try_new(&stream_handle).unwrap();
sink.append(source);
sink.sleep_until_end();

You can tweak the speaker's parameters via Speaker::params. Each change will only affect the given speaker. This is unlike eSpeak NG's API where a parameter change is global:

let mut speaker = espeaker::Speaker::new();
speaker.params.pitch = Some(400);
speaker.params.rate = Some(80);

This library also supports callbacks that can be used when certain speech landmarks like words or sentences are spoken. Use the SpeakerSource::with_callback method to create a new source that dispatches the callback:

let mut speaker = espeaker::Speaker::new();
speaker.params.rate = Some(280);
let source = speaker.speak("Hello world, goodbye!");
let source = source.with_callback(move |evt| match evt {
    espeaker::Event::Word(start, _len) => {
        println!("'Word at {}'", start);
    }
    espeaker::Event::Sentence(_) => (),
    espeaker::Event::End => {
        println!("'End!");
    }
});

Dependencies

~2–37MB
~531K SLoC