mirror of https://github.com/ndarilek/tts-rs.git
Add basic documentation.
This commit is contained in:
parent
863ae0e8c3
commit
96722d7032
33
src/lib.rs
33
src/lib.rs
|
@ -1,3 +1,8 @@
|
||||||
|
/*!
|
||||||
|
* a Text-To-Speech (TTS) library providing high-level interfaces to a variety of backends.
|
||||||
|
* Currently supported backends are [Speech Dispatcher](https://freebsoft.org/speechd) (Linux).
|
||||||
|
*/
|
||||||
|
|
||||||
use std::boxed::Box;
|
use std::boxed::Box;
|
||||||
|
|
||||||
mod backends;
|
mod backends;
|
||||||
|
@ -21,6 +26,10 @@ trait Backend {
|
||||||
pub struct TTS(Box<Backend>);
|
pub struct TTS(Box<Backend>);
|
||||||
|
|
||||||
impl TTS {
|
impl TTS {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new `TTS` instance with the specified backend.
|
||||||
|
*/
|
||||||
pub fn new(backend: Backends) -> TTS {
|
pub fn new(backend: Backends) -> TTS {
|
||||||
match backend {
|
match backend {
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
|
@ -28,38 +37,62 @@ impl TTS {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Speaks the specified text, optionally interrupting current speech.
|
||||||
|
*/
|
||||||
pub fn speak<S: Into<String>>(&self, text: S, interrupt: bool) -> &Self {
|
pub fn speak<S: Into<String>>(&self, text: S, interrupt: bool) -> &Self {
|
||||||
self.0.speak(text.into().as_str(), interrupt);
|
self.0.speak(text.into().as_str(), interrupt);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops current speech.
|
||||||
|
*/
|
||||||
pub fn stop(&self) -> &Self {
|
pub fn stop(&self) -> &Self {
|
||||||
self.0.stop();
|
self.0.stop();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the current speech rate.
|
||||||
|
*/
|
||||||
pub fn get_rate(&self) -> u8 {
|
pub fn get_rate(&self) -> u8 {
|
||||||
self.0.get_rate()
|
self.0.get_rate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the desired speech rate.
|
||||||
|
*/
|
||||||
pub fn set_rate(&self, rate: u8) -> &Self {
|
pub fn set_rate(&self, rate: u8) -> &Self {
|
||||||
self.0.set_rate(rate);
|
self.0.set_rate(rate);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the current speech pitch.
|
||||||
|
*/
|
||||||
pub fn get_pitch(&self) -> u8 {
|
pub fn get_pitch(&self) -> u8 {
|
||||||
self.0.get_pitch()
|
self.0.get_pitch()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the desired speech pitch.
|
||||||
|
*/
|
||||||
pub fn set_pitch(&self, pitch: u8) -> &Self {
|
pub fn set_pitch(&self, pitch: u8) -> &Self {
|
||||||
self.0.set_pitch(pitch);
|
self.0.set_pitch(pitch);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the current speech volume.
|
||||||
|
*/
|
||||||
pub fn get_volume(&self) -> u8 {
|
pub fn get_volume(&self) -> u8 {
|
||||||
self.0.get_volume()
|
self.0.get_volume()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the desired speech volume.
|
||||||
|
*/
|
||||||
pub fn set_volume(&self, volume: u8) -> &Self {
|
pub fn set_volume(&self, volume: u8) -> &Self {
|
||||||
self.0.set_volume(volume);
|
self.0.set_volume(volume);
|
||||||
self
|
self
|
||||||
|
|
Loading…
Reference in New Issue