batch_mode_tts/clip.rs
1crate::ix!();
2
3/// ---------------------------------------------------------------------------
4/// Clip a string to at most `max_chars` characters (not bytes).
5/// ---------------------------------------------------------------------------
6pub fn clip_to_chars(input: &str, max_chars: usize) -> String {
7 if input.chars().count() <= max_chars {
8 tracing::debug!("Input length {} chars, no clipping needed", input.chars().count());
9 input.to_owned()
10 } else {
11 let clipped: String = input.chars().take(max_chars).collect();
12 tracing::warn!(
13 "Clipped input text from {} chars to {} chars",
14 input.chars().count(),
15 max_chars
16 );
17 clipped
18 }
19}