1
0
mirror of https://github.com/ndarilek/tts-rs.git synced 2024-11-17 12:49:38 +00:00

Merge branch 'master' of https://github.com/ndarilek/tts-rs into master

This commit is contained in:
Nolan Darilek 2020-09-02 15:52:43 -05:00
commit 2cfd2ea09e

View File

@ -28,7 +28,25 @@ impl Backend for Tolk {
fn speak(&mut self, text: &str, interrupt: bool) -> Result<(), Error> {
trace!("speak({}, {})", text, interrupt);
self.0.speak(text, interrupt);
const BUFFER_LENGTH: usize = 300;
if text.len() <= BUFFER_LENGTH {
self.0.speak(text, interrupt);
} else {
if interrupt {
self.stop()?;
}
let tokens = text.split_whitespace();
let mut buffer = String::new();
for token in tokens {
if buffer.len() + token.len() > BUFFER_LENGTH {
self.0.speak(buffer, false);
buffer = String::new();
} else {
buffer.push_str(token);
buffer.push(' ');
}
}
}
Ok(())
}