add save sound
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
getSessionAnnouncementText,
|
||||
handleSessionTimerTickHelper,
|
||||
selectSpeechVoice,
|
||||
speakTextHelper,
|
||||
} from "../src/runtime_services.js";
|
||||
|
||||
test("speech voice selection prefers an explicit voice and then the current language", () => {
|
||||
@@ -88,3 +89,37 @@ test("session timer emits each race-audio clock marker once without changing fin
|
||||
assert.ok(active.followUpStartedAt);
|
||||
assert.ok(saves >= 4);
|
||||
});
|
||||
|
||||
test("race audio can ignore a mismatched configured voice and select the announcement language", () => {
|
||||
const originalWindow = globalThis.window;
|
||||
const OriginalUtterance = globalThis.SpeechSynthesisUtterance;
|
||||
const spoken = [];
|
||||
const voices = [
|
||||
{ name: "English", lang: "en-US", voiceURI: "voice-en", localService: true },
|
||||
{ name: "Swedish", lang: "sv-SE", voiceURI: "voice-sv", localService: true },
|
||||
];
|
||||
globalThis.window = {
|
||||
speechSynthesis: {
|
||||
speaking: false,
|
||||
pending: false,
|
||||
cancel() {},
|
||||
getVoices: () => voices,
|
||||
speak: (utterance) => spoken.push(utterance),
|
||||
},
|
||||
};
|
||||
globalThis.SpeechSynthesisUtterance = class {
|
||||
constructor(text) { this.text = text; }
|
||||
};
|
||||
try {
|
||||
const started = speakTextHelper("Race finished", {
|
||||
state: { settings: { audioEnabled: true, speechVoiceUri: "voice-sv", speechRate: 1, speechPitch: 1 } },
|
||||
currentLanguage: () => "sv",
|
||||
}, { language: "en", voiceUri: "" });
|
||||
assert.equal(started, true);
|
||||
assert.equal(spoken[0].lang, "en-US");
|
||||
assert.equal(spoken[0].voice.voiceURI, "voice-en");
|
||||
} finally {
|
||||
globalThis.window = originalWindow;
|
||||
globalThis.SpeechSynthesisUtterance = OriginalUtterance;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user