7 releases
0.1.6 | Aug 28, 2024 |
---|---|
0.1.5 | Feb 9, 2024 |
0.1.4 | Jan 26, 2024 |
0.1.2 | Nov 22, 2023 |
0.1.0 | Jul 19, 2022 |
#247 in Audio
20KB
431 lines
eSpeak NG playback library
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::Start => {
println!("'Start!")
}
espeaker::Event::End => {
println!("'End!");
}
});
Dependencies
~2–32MB
~502K SLoC