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

#233 in Audio

Download history 5/week @ 2023-11-12 35/week @ 2023-11-19 25/week @ 2023-11-26 10/week @ 2023-12-03 3/week @ 2023-12-10 4/week @ 2023-12-17 6/week @ 2023-12-24 39/week @ 2023-12-31 12/week @ 2024-01-07 12/week @ 2024-01-14 74/week @ 2024-01-21 27/week @ 2024-01-28 41/week @ 2024-02-04 58/week @ 2024-02-11 189/week @ 2024-02-18

320 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

~1–34MB
~479K SLoC