feat(audio): speak lap times as seconds and hundredths, "18 sixty-three" (1.89.2)

This commit is contained in:
larssand committed 2026-11-10 18:45:04 +01:00
1 parent 379dd52c7f
commit dd2fc6bd89
7 files changed
+37 -14

No files matched your search

+2 -2
View File
@@ -3,7 +3,7 @@ import { getControlledLapStreak } from "./training_logic.js";
import { usesPersonalClock, getLatestClockStartTs } from "./prologue_logic.js";
import { isSuspectLap, getSuspectReferenceLaps, releaseSettledSuspectLaps } from "./suspect_laps_logic.js";
import { shouldCallPracticePersonalBest } from "./practice_callouts_logic.js";
import { normalizeRaceAudioSettings, formatSpokenLapTime, formatShortLapCall, LEADER_UPDATE_INTERVAL_MS } from "./race_audio.js";
import { normalizeRaceAudioSettings, formatSpokenLapTime, formatSpokenGap, formatShortLapCall, LEADER_UPDATE_INTERVAL_MS } from "./race_audio.js";
import { findDriverByCarTransponder } from "./sponsor_event_logic.js";
import { confirmLeaderChange } from "./leader_call_logic.js";
import { pickPracticeHype, getDriverLapTimes, getClassRank, getLastTimeBestMs, findDuelRival } from "./practice_hype_logic.js";
@@ -46,7 +46,7 @@ function buildPracticeHype({ state, session, result, entry, key, lapMs, previous
const en = language === "en";
const v = pick.variables;
const variables = { driverName: spokenName(entry), laps: v.laps, rival: v.rival };
if (v.gapMs !== undefined) variables.gap = formatSpokenLapTime(Math.max(10, v.gapMs), language);
if (v.gapMs !== undefined) variables.gap = formatSpokenGap(Math.max(10, v.gapMs), language);
if (v.avgMs) variables.avgLap = formatSpokenLapTime(v.avgMs, language);
if (v.rank) variables.rank = (en ? ["the fastest", "second fastest", "third fastest"] : ["snabbast", "näst snabbast", "tredje snabbast"])[v.rank - 1];
if (v.ahead !== undefined) variables.relation = v.ahead ? (en ? "ahead of" : "före") : (en ? "behind" : "efter");
+18 -2
View File
@@ -150,9 +150,25 @@ export function formatShortLapCall(ms, language = "sv") {
return minutes ? `${minutes} ${String(seconds).padStart(2, "0")} ${tenth}` : `${seconds} ${tenth}`;
}
// A lap time as the speaker says it: "17,18" (sv) / "17.18" (en), not "0:17.180", which voices
// read as "zero 17 comma 180". Hundredths, cut not rounded, as on the timing screens.
// A lap time as a speaker says it: seconds and hundredths as two numbers, "18 63" -> "18
// sixty-three" ("18 sextiotre"), not "0:18.630" or "18 point six three". Over a minute:
// "1 minut 05 32". Hundredths are cut, not rounded, as on the timing screens.
export function formatSpokenLapTime(ms, language = "sv") {
const value = Math.max(0, Math.floor(Number(ms) || 0));
if (!value) return "";
const minutes = Math.floor(value / 60000);
const seconds = Math.floor((value % 60000) / 1000);
// "00" would be read "hundred" by some voices: say "flat" / "jämnt" as on the passing call.
const cut = Math.floor((value % 1000) / 10);
const hundredths = cut ? String(cut).padStart(2, "0") : TENTHS[language === "en" ? "en" : "sv"][0];
if (!minutes) return `${seconds} ${hundredths}`;
const word = language === "en" ? (minutes === 1 ? "minute" : "minutes") : (minutes === 1 ? "minut" : "minuter");
return `${minutes} ${word} ${String(seconds).padStart(2, "0")} ${hundredths}`;
}
// A gap or other short time with a decimal mark: "0,30" (sv) / "0.30" (en), read as "zero
// point three zero" - a gap said as "0 30" would sound like a clock.
export function formatSpokenGap(ms, language = "sv") {
const value = Math.max(0, Math.floor(Number(ms) || 0));
if (!value) return "";
const minutes = Math.floor(value / 60000);