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:
commit
2cfd2ea09e
|
@ -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(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user