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

+39 -1
View File
@@ -1,6 +1,6 @@
import test from "node:test";
import assert from "node:assert/strict";
import { RACE_AUDIO_EVENT_DEFINITIONS, createRaceAudioEngine, normalizeRaceAudioSettings, isSilencedDuringRace, formatSpokenLapTime } from "../src/race_audio.js";
import { RACE_AUDIO_EVENT_DEFINITIONS, createRaceAudioEngine, normalizeRaceAudioSettings, isSilencedDuringRace, formatSpokenLapTime, formatShortLapCall } from "../src/race_audio.js";
const manifest = {
events: { transponder_pass: { effect: "effects/transponder_pass.wav" }, start_tone: { effect: "effects/start_beep.wav" } },
@@ -346,3 +346,41 @@ test("practice hype calls only sound in practice and can be turned off", () => {
});
assert.equal(isSilencedDuringRace("practice_close_to_best", { practiceHype: false }, { type: "open_practice" }), true);
});
test("quick lap time call: seconds and tenths, practice only and without the name by default", () => {
assert.equal(formatShortLapCall(17620, "en"), "17 six");
assert.equal(formatShortLapCall(18040, "en"), "18 flat");
assert.equal(formatShortLapCall(18290, "sv"), "18 två");
assert.equal(formatShortLapCall(18000, "sv"), "18 jämnt");
assert.equal(formatShortLapCall(65200, "en"), "1 05 two");
const audio = normalizeRaceAudioSettings({});
assert.equal(audio.lapTimeCalls, "practice");
assert.equal(audio.lapTimeCallName, false);
assert.equal(isSilencedDuringRace("lap_completed", {}, { type: "open_practice" }), false);
assert.equal(isSilencedDuringRace("lap_completed", {}, { type: "final" }), true);
assert.equal(isSilencedDuringRace("lap_completed", { lapTimeCalls: "always" }, { type: "final" }), false);
assert.equal(isSilencedDuringRace("lap_completed", { lapTimeCalls: "off" }, { type: "open_practice" }), true);
});
test("a quick lap time call is dropped while the voice is busy", async () => {
const spoken = [];
let finish;
const engine = createRaceAudioEngine({
fetchImpl: async () => ({ ok: true, json: async () => manifest }),
audioFactory: () => ({ play: () => Promise.resolve(), volume: 1 }),
speak: (text) => { spoken.push(text); return new Promise((resolve) => { finish = resolve; }); },
wait: async () => {},
getSettings: () => normalizeRaceAudioSettings({}),
});
engine.trigger("audio_test", { voiceText: "busy" });
await new Promise((resolve) => setTimeout(resolve, 10));
const lap = await engine.trigger("lap_completed", { skipIfBusy: true, voiceText: "{lapShort}", variables: { lapShort: "17 six" } }).voiceDone;
assert.equal(lap, false);
finish(true);
await new Promise((resolve) => setTimeout(resolve, 10));
const free = await engine.trigger("lap_completed", { skipIfBusy: true, voiceText: "{lapShort}", variables: { lapShort: "18 flat" } });
await new Promise((resolve) => setTimeout(resolve, 10));
finish(true);
assert.equal(await free.voiceDone, true);
assert.deepEqual(spoken, ["busy", "18 flat"]);
});