Skip to content

Commit c2d31eb

Browse files
committed
fix: resolve linting and TypeScript errors in blind mode audio
- Prefix unused variables with underscore (_isSpeaking, _currentWordIndex, _totalWords) - Fix audioContext possibly undefined by capturing context in const - Add void operator for floating promise - Add missing commandline metadata for blindModeAudioFeedback and blindModeSpeechRate These fixes resolve all build errors while maintaining functionality.
1 parent 9f46b31 commit c2d31eb

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

frontend/src/ts/commandline/commandline-metadata.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,16 @@ export const commandlineConfigMetadata: CommandlineConfigMetadataObject = {
210210
options: "fromSchema",
211211
},
212212
},
213+
blindModeAudioFeedback: {
214+
subgroup: {
215+
options: "fromSchema",
216+
},
217+
},
218+
blindModeSpeechRate: {
219+
input: {
220+
inputValueConvert: Number,
221+
},
222+
},
213223
alwaysShowWordsHistory: {
214224
subgroup: {
215225
options: "fromSchema",

frontend/src/ts/controllers/blind-mode-audio-controller.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import * as SoundController from "./sound-controller";
55

66
let voice: SpeechSynthesisUtterance | undefined;
77
let isInitialized = false;
8-
let isSpeaking = false;
9-
let currentWordIndex = -1;
10-
let totalWords = 0;
8+
let _isSpeaking = false;
9+
let _currentWordIndex = -1;
10+
let _totalWords = 0;
1111

1212
// Audio oscillator for additional feedback
1313
let audioContext: AudioContext | undefined;
@@ -33,22 +33,22 @@ export async function init(): Promise<void> {
3333
await initAudioContext();
3434

3535
isInitialized = true;
36-
currentWordIndex = -1;
37-
totalWords = 0;
36+
_currentWordIndex = -1;
37+
_totalWords = 0;
3838
}
3939

4040
export function clear(): void {
4141
window.speechSynthesis.cancel();
4242
voice = undefined;
4343
isInitialized = false;
44-
isSpeaking = false;
45-
currentWordIndex = -1;
46-
totalWords = 0;
44+
_isSpeaking = false;
45+
_currentWordIndex = -1;
46+
_totalWords = 0;
4747
}
4848

4949
export function stop(): void {
5050
window.speechSynthesis.cancel();
51-
isSpeaking = false;
51+
_isSpeaking = false;
5252
}
5353

5454
async function speak(text: string, rate?: number): Promise<void> {
@@ -60,13 +60,13 @@ async function speak(text: string, rate?: number): Promise<void> {
6060
voice.text = text;
6161
voice.rate = rate ?? Config.blindModeSpeechRate;
6262

63-
isSpeaking = true;
63+
_isSpeaking = true;
6464

6565
window.speechSynthesis.speak(voice);
6666

6767
// Wait for speech to end
6868
voice.onend = () => {
69-
isSpeaking = false;
69+
_isSpeaking = false;
7070
};
7171
}
7272

@@ -133,7 +133,7 @@ export async function announceNextWord(word: string, wordIndex: number): Promise
133133
if (Config.blindModeAudioFeedback === "off") return;
134134
if (!Config.blindMode) return;
135135

136-
currentWordIndex = wordIndex;
136+
_currentWordIndex = wordIndex;
137137

138138
if (Config.blindModeAudioFeedback === "full") {
139139
// In full mode, speak each word
@@ -192,7 +192,7 @@ export async function announceWordCompletion(isCorrect: boolean): Promise<void>
192192
export async function announceTestStart(
193193
mode: string,
194194
value: number,
195-
language: string
195+
_language: string
196196
): Promise<void> {
197197
if (Config.blindModeAudioFeedback === "off") return;
198198
if (!Config.blindMode) return;
@@ -201,7 +201,7 @@ export async function announceTestStart(
201201
if (mode === "time") {
202202
await speak(`${value} second test starting`);
203203
} else if (mode === "words") {
204-
totalWords = value;
204+
_totalWords = value;
205205
await speak(`${value} word test starting`);
206206
} else {
207207
await speak("Test starting");
@@ -228,19 +228,20 @@ export async function announceTestComplete(
228228
} else if (Config.blindModeAudioFeedback === "minimal") {
229229
// Play a completion sound sequence
230230
if (audioContext) {
231+
const ctx = audioContext;
231232
const playNote = (freq: number, delay: number): void => {
232233
setTimeout(() => {
233-
const oscillator = audioContext.createOscillator();
234-
const gainNode = audioContext.createGain();
234+
const oscillator = ctx.createOscillator();
235+
const gainNode = ctx.createGain();
235236

236237
oscillator.connect(gainNode);
237-
gainNode.connect(audioContext.destination);
238+
gainNode.connect(ctx.destination);
238239

239240
oscillator.frequency.value = freq;
240241
gainNode.gain.value = 0.15 * Config.soundVolume;
241242

242243
oscillator.start();
243-
oscillator.stop(audioContext.currentTime + 0.15);
244+
oscillator.stop(ctx.currentTime + 0.15);
244245
}, delay);
245246
};
246247

@@ -264,7 +265,7 @@ export async function announceTimeWarning(secondsLeft: number): Promise<void> {
264265
}
265266

266267
// Always play the time warning sound
267-
SoundController.playTimeWarning();
268+
void SoundController.playTimeWarning();
268269
}
269270

270271
/**

0 commit comments

Comments
 (0)