feat(audio): quick lap time call at each passing, 17 six / 18 flat (1.62.0)

This commit is contained in:
larssand committed 2026-11-05 18:14:30 +01:00
1 parent 94ec278f53
commit 6142b14e47
10 files changed
+101 -10

No files matched your search

+12
View File
@@ -2531,6 +2531,12 @@ const TRANSLATIONS = {
"audio.practice_pb_warmup": "Träning: tyst personbästa första varven",
"audio.practice_pb_cooldown": "Träning: sekunder mellan PB-utrop per förare",
"audio.practice_pb_min_gain": "Träning: minsta förbättring för utrop (s)",
"audio.lap_time_calls": "Varvtid vid passering",
"audio.lap_time_calls_hint": "Kort varvtid vid varje passering, som på stora race: 17 sex, 18 jämnt. Sägs bara när rösten är ledig och inget annat ropas för varvet.",
"audio.lap_time_calls_practice": "Bara träning",
"audio.lap_time_calls_always": "Träning och race",
"audio.lap_time_calls_off": "Av",
"audio.lap_time_call_name": "Säg namnet före varvtiden",
"audio.practice_hype": "Peppande träningsutrop",
"audio.practice_hype_hint": "Bara i träning, aldrig i kval eller final: varvjubileum, nära bästa varvet, snittet går ner, snabbare varv i rad, snabbare än förra gången, placering i klassen och dueller. Varje utrop kan också stängas av i listan nedan.",
"audio.race_leader_calls": "Ledare i kval och final",
@@ -4518,6 +4524,12 @@ const TRANSLATIONS = {
"audio.practice_pb_warmup": "Practice: silent personal best for first laps",
"audio.practice_pb_cooldown": "Practice: seconds between PB calls per driver",
"audio.practice_pb_min_gain": "Practice: minimum improvement to call (s)",
"audio.lap_time_calls": "Lap time at each passing",
"audio.lap_time_calls_hint": "A quick lap time at each passing, as at big races: 17 six, 18 flat. Only said when the voice is free and nothing else is called for that lap.",
"audio.lap_time_calls_practice": "Practice only",
"audio.lap_time_calls_always": "Practice and races",
"audio.lap_time_calls_off": "Off",
"audio.lap_time_call_name": "Say the name before the lap time",
"audio.practice_hype": "Practice hype calls",
"audio.practice_hype_hint": "Practice only, never in qualifying or finals: lap milestones, close to best, average going down, faster laps in a row, faster than last time, class rank and duels. Each call can also be turned off in the list below.",
"audio.race_leader_calls": "Leader in qualifying and finals",
+12 -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, LEADER_UPDATE_INTERVAL_MS } from "./race_audio.js";
import { normalizeRaceAudioSettings, formatSpokenLapTime, formatShortLapCall, LEADER_UPDATE_INTERVAL_MS } from "./race_audio.js";
import { pickPracticeHype, getDriverLapTimes, getClassRank, getLastTimeBestMs, findDuelRival } from "./practice_hype_logic.js";
import { decoderClockCheck, describeDecoderClockSkew } from "./decoder_clock_check.js";
import { getCompetitorEndTs } from "./timing_logic.js";
@@ -642,10 +642,20 @@ export function processDecoderMessageHelper(msg, deps, decoderRole = "main") {
if (callPersonalBest) triggerRaceAudio("personal_best", { variables: audioVariables, driverId: entry.driverId, competitorKey: key, logData: { raceId: session.eventId, driverId: entry.driverId, lapNumber: entry.laps, lapTime: lapMs } });
if (!suspect && previousSessionFastest && lapMs < previousSessionFastest) triggerRaceAudio("fastest_lap", { variables: audioVariables, driverId: entry.driverId, competitorKey: key, logData: { raceId: session.eventId, driverId: entry.driverId, lapNumber: entry.laps, lapTime: lapMs } });
if (!suspect && previousTrackRecord && lapMs < previousTrackRecord) triggerRaceAudio("track_record", { variables: audioVariables, driverId: entry.driverId, competitorKey: key, logData: { raceId: session.eventId, driverId: entry.driverId, lapNumber: entry.laps, lapTime: lapMs } });
let hype = null;
if (isPracticeSession && entry.driverId && !suspect && !validationWarning) {
const hype = buildPracticeHype({ state, session, result, entry, key, lapMs, previousPersonalBest, memoryKey: pbCallKey, timestamp });
hype = buildPracticeHype({ state, session, result, entry, key, lapMs, previousPersonalBest, memoryKey: pbCallKey, timestamp });
if (hype) triggerRaceAudio(hype.key, { variables: hype.variables, driverId: entry.driverId, competitorKey: key, logData: { raceId: session.eventId, sessionId: session.id, driverId: entry.driverId, lapNumber: entry.laps, lapTime: lapMs } });
}
// The quick lap time, "Anders, 17 six": only when nothing else is called for this lap and the
// voice is free (race_audio.js decides practice / always / off).
const calledThisLap = callPersonalBest || hype
|| (!suspect && previousSessionFastest && lapMs < previousSessionFastest) || (!suspect && previousTrackRecord && lapMs < previousTrackRecord);
if (!calledThisLap && !validationWarning && lapMs > 500) {
const audio = normalizeRaceAudioSettings(state.settings?.raceAudio);
const driverPrefix = audio.lapTimeCallName && spokenName(entry) ? `${spokenName(entry)}, ` : "";
triggerRaceAudio("lap_completed", { skipIfBusy: true, variables: { driverPrefix, driverName: spokenName(entry), lapShort: formatShortLapCall(lapMs, audio.language) }, driverId: entry.driverId, competitorKey: key });
}
if (previousPosition >= 0 && currentPosition >= 0 && currentPosition < previousPosition) triggerRaceAudio("position_gain", { driverId: entry.driverId, competitorKey: key });
if (previousPosition >= 0 && currentPosition > previousPosition) triggerRaceAudio("position_loss", { driverId: entry.driverId, competitorKey: key });
const leader = leaderboard[0];
+20 -1
View File
@@ -17,7 +17,7 @@ export const RACE_AUDIO_EVENT_DEFINITIONS = Object.freeze([
event("prologue_hold", "start", "high", true, "effects/warning.wav"), event("prologue_resumed", "start", "normal"),
event("prologue_cancelled", "start", "normal"), event("clock_running", "start", "high"),
event("heat_call", "start", "normal"),
event("transponder_pass", "race", "pass", false, "effects/transponder_pass.wav"), event("lap_completed", "race", "pass", false),
event("transponder_pass", "race", "pass", false, "effects/transponder_pass.wav"), event("lap_completed", "race", "pass"),
event("personal_best", "race", "low", true, "effects/personal_best.wav", 1500),
event("fastest_lap", "race", "normal", true, "effects/fastest_lap_trophy.wav", 1500),
event("track_record", "race", "normal", true, "effects/track_record_fanfare.wav", 2000),
@@ -99,6 +99,9 @@ export function normalizeRaceAudioSettings(value = {}) {
raceCallouts: source.raceCallouts === "full" ? "full" : "passing",
// Practice hype calls (practice_hype_logic.js); never in qualifying or finals.
practiceHype: source.practiceHype !== false,
// Short lap time per passing, "Anders, 17 six": "practice" (default), "always" or "off".
lapTimeCalls: ["practice", "always", "off"].includes(source.lapTimeCalls) ? source.lapTimeCalls : "practice",
lapTimeCallName: source.lapTimeCallName === true,
// Qualifying and finals: "both" = when the leader changes and every 2 minutes,
// "change" = only when the leader changes, "off" = never (unless raceCallouts is "full").
raceLeaderCalls: ["off", "change", "both"].includes(source.raceLeaderCalls) ? source.raceLeaderCalls : "both",
@@ -125,6 +128,7 @@ export function isSilencedDuringRace(eventKey, settings, session) {
const audio = normalizeRaceAudioSettings(settings);
const practice = Boolean(session) && PRACTICE_TYPES.has(String(session.type || ""));
if (PRACTICE_HYPE_SET.has(eventKey)) return !practice || !audio.practiceHype;
if (eventKey === "lap_completed") return audio.lapTimeCalls === "off" || (audio.lapTimeCalls === "practice" && !practice);
if (!session || practice) return false;
if (eventKey === "leader_update") return audio.raceLeaderCalls !== "both";
if (eventKey === "new_leader" && audio.raceLeaderCalls !== "off") return false;
@@ -132,6 +136,18 @@ export function isSilencedDuringRace(eventKey, settings, session) {
return RACE_PASSING_CALLOUT_EVENTS.includes(eventKey);
}
// The quick passing call used at race tracks: seconds and tenths, "17 six", "18 flat"
// ("17 sex", "18 jämnt"). Over a minute: "1 05 two".
const TENTHS = { en: ["flat", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"], sv: ["jämnt", "ett", "två", "tre", "fyra", "fem", "sex", "sju", "åtta", "nio"] };
export function formatShortLapCall(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);
const tenth = TENTHS[language === "en" ? "en" : "sv"][Math.floor((value % 1000) / 100)];
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.
export function formatSpokenLapTime(ms, language = "sv") {
@@ -263,6 +279,9 @@ export function createRaceAudioEngine(options = {}) {
async function enqueueVoice(key, eventOptions = {}) {
const voice = await resolveVoice(key, eventOptions);
if (!voice) return false;
// Quick calls (the lap time per passing) are only said when the voice is free: a lap time
// said late is worse than none.
if (eventOptions.skipIfBusy && (currentVoice || voiceQueue.length)) return false;
return new Promise((resolve) => {
const group = String(eventOptions.group || "");
const task = { ...voice, group, sequence: voiceSequence += 1, resolve, expiresAt: eventOptions.maxDelayMs ? Number(eventOptions.queuedAt ?? now()) + Number(eventOptions.maxDelayMs) : 0 };
+6 -2
View File
@@ -2,7 +2,7 @@ import { normalizePublicBaseUrl } from "./public_url.js";
import { decoderDiagnosticsMarkup, mountDecoderDiagnostics } from "./decoder_diagnostics_view.js";
import { mountAuthSettings } from "./auth_view.js";
import { mountTtsSettings } from "./tts_settings_view.js";
import { formatSpokenLapTime } from "./race_audio.js";
import { formatSpokenLapTime, formatShortLapCall } from "./race_audio.js";
let activeSettingsTab = "connection";
let pendingSettingsFocusId = "";
@@ -253,6 +253,8 @@ export function renderSettings(deps) {
<label class="toggle"><input type="checkbox" name="raceAudioMuted" form="settingsForm" ${raceAudio.muted ? "checked" : ""} /><span>${t("audio.mute")}</span></label>
<label><span>${t("audio.race_callouts")}</span><select name="raceAudioRaceCallouts" form="settingsForm"><option value="passing" ${raceAudio.raceCallouts === "passing" ? "selected" : ""}>${t("audio.race_callouts_passing")}</option><option value="full" ${raceAudio.raceCallouts === "full" ? "selected" : ""}>${t("audio.race_callouts_full")}</option></select></label>
<label class="toggle" title="${t("audio.practice_hype_hint")}"><input type="checkbox" name="raceAudioPracticeHype" form="settingsForm" ${raceAudio.practiceHype ? "checked" : ""} /><span>${t("audio.practice_hype")}</span></label>
<label title="${t("audio.lap_time_calls_hint")}"><span>${t("audio.lap_time_calls")}</span><select name="raceAudioLapTimeCalls" form="settingsForm">${["practice", "always", "off"].map((value) => `<option value="${value}" ${raceAudio.lapTimeCalls === value ? "selected" : ""}>${t("audio.lap_time_calls_" + value)}</option>`).join("")}</select></label>
<label class="toggle"><input type="checkbox" name="raceAudioLapTimeCallName" form="settingsForm" ${raceAudio.lapTimeCallName ? "checked" : ""} /><span>${t("audio.lap_time_call_name")}</span></label>
<label><span>${t("audio.race_leader_calls")}</span><select name="raceAudioLeaderCalls" form="settingsForm">${["both", "change", "off"].map((value) => `<option value="${value}" ${raceAudio.raceLeaderCalls === value ? "selected" : ""}>${t("audio.race_leader_" + value)}</option>`).join("")}</select></label>
<label title="${t("audio.practice_pb_hint")}"><span>${t("audio.practice_pb_warmup")}</span><input type="number" min="0" max="30" step="1" name="raceAudioPbWarmup" form="settingsForm" value="${raceAudio.practicePbWarmupLaps}" /></label>
<label title="${t("audio.practice_pb_hint")}"><span>${t("audio.practice_pb_cooldown")}</span><input type="number" min="0" max="600" step="10" name="raceAudioPbCooldown" form="settingsForm" value="${raceAudio.practicePbCooldownSec}" /></label>
@@ -640,6 +642,8 @@ Erik Eriksson;654321;4WD;Associated;;</code></pre>
maxStartDelay: Number(form.get("raceAudioMaxDelay")), perCompetitorPassingTone: form.get("raceAudioPerCompetitor") === "on",
raceCallouts: String(form.get("raceAudioRaceCallouts") || "passing"),
practiceHype: form.get("raceAudioPracticeHype") === "on",
lapTimeCalls: String(form.get("raceAudioLapTimeCalls") || "practice"),
lapTimeCallName: form.get("raceAudioLapTimeCallName") === "on",
raceLeaderCalls: String(form.get("raceAudioLeaderCalls") || "both"),
startSound: String(form.get("raceAudioStartSound") || "tone"),
finishSound: String(form.get("raceAudioFinishSound") || "stop"),
@@ -742,7 +746,7 @@ Erik Eriksson;654321;4WD;Associated;;</code></pre>
// matches what you're about to hear - but a test playback is not itself a reason to
// write those still-unsaved changes to the database. Use the explicit Save button for that.
applyRaceAudioFormValuesFromDom();
triggerRaceAudio(eventKey, { force: true, interrupt: true, variables: { driverName: state.drivers[0]?.name || "Driver", lapTime: formatSpokenLapTime(16000, state.settings.raceAudio?.language), avgLap: formatSpokenLapTime(16420, state.settings.raceAudio?.language), laps: 5, marshalPost: "1", transponder: "123", podium: "P1, P2, P3" } });
triggerRaceAudio(eventKey, { force: true, interrupt: true, variables: { driverName: state.drivers[0]?.name || "Driver", lapTime: formatSpokenLapTime(16000, state.settings.raceAudio?.language), lapShort: formatShortLapCall(17620, state.settings.raceAudio?.language), driverPrefix: state.settings.raceAudio?.lapTimeCallName ? `${state.drivers[0]?.name || "Driver"}, ` : "", avgLap: formatSpokenLapTime(16420, state.settings.raceAudio?.language), laps: 5, marshalPost: "1", transponder: "123", podium: "P1, P2, P3" } });
};
document.getElementById("settingsRaceAudioTest")?.addEventListener("click", () => testRaceAudio("audio_test"));
document.querySelectorAll("[data-test-race-audio]").forEach((button) => button.addEventListener("click", () => testRaceAudio(button.dataset.testRaceAudio)));