Skip to content

Commit 1e09cea

Browse files
committed
inference/tts: fix speedup calculation
VitsTts returns duration in seconds, but our speedup divides by elapsed time in milliseconds, causing the speedup to be 1000x too low. We could divide by the elapsed time in seconds to fix this, but that would not be very precise, and as VitsTts could return 0 for very short audio, we could return speedup 0. Instead, calculate the duration in milliseconds from samples and sample rate, and use that to calculate speedup. Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
1 parent 1ea4304 commit 1e09cea

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/inference/tts.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,16 @@ impl TtsEngine {
5656

5757
let time = start.elapsed().as_secs_f64();
5858
let time_ms = time * 1000.0;
59+
let duration = (speech.samples.len() as u64 * 1000) / u64::from(speech.sample_rate);
5960
#[allow(clippy::cast_precision_loss)]
60-
let speedup = if time_ms > 0.0 {
61-
(f64::from(speech.duration)) / time_ms
61+
let speedup = if time > 0.0 {
62+
duration as f64 / time_ms
6263
} else {
6364
0.0
6465
};
6566

6667
let result = InferenceResult {
67-
duration: u64::try_from(speech.duration).unwrap_or(0),
68+
duration,
6869
output: speech,
6970
speedup,
7071
time,

0 commit comments

Comments
 (0)